# 5. Developer Extension API

The Admin Activity Log provides a public PHP extension API that allows developers to register custom entities for activity logging. Registered entities appear automatically in the plugin configuration and are fully captured in the activity log.

## Implementing the Interface

Create a class that implements `TrackableEntityProviderInterface`:

```php
use Momocode\MomoAdminActivityLog\Extension\TrackableEntityProviderInterface;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityWriteResult;

class MyCustomEntityProvider implements TrackableEntityProviderInterface
{
    public function getEntityName(): string
    {
        // DAL entity name (matches the table name)
        return 'my_custom_entity';
    }

    public function getLabel(): string
    {
        // Human-readable label shown in the plugin configuration
        return 'My Custom Entity';
    }

    public function resolveDisplayName(string $entityId, EntityWriteResult $writeResult, Context $context): ?string
    {
        // Optional: return a human-readable display name for a log entry.
        // Called when a log entry is created.
        // Return null if no name can be resolved (falls back to the entity ID).
        return null;
    }

    public function getAdminRoute(): ?string
    {
        // Optional: Vue Router route to the entity's detail page.
        // Used for deep-links in the activity log listing.
        // Format: 'sw.my.custom.entity.detail'
        // Return null if no detail page exists.
        return null;
    }
}
```

## Registering the Service

Register the provider in your `services.xml` with the `momo.activity_log.entity_provider` tag:

```xml
<service id="MyVendor\MyPlugin\ActivityLog\MyCustomEntityProvider">
    <tag name="momo.activity_log.entity_provider" entity="my_custom_entity"/>
</service>
```

That's all — the plugin's compiler pass registers the provider automatically. On the next container build, the entity is included in the activity log.

## Result

After registration:

* The entity appears in the plugin configuration under **Tracked Entities** and can be enabled or disabled there
* All writes to this entity are automatically logged when it is selected in the configuration
* Display names (if `resolveDisplayName()` is implemented) are shown in the listing view
* Deep-links (if `getAdminRoute()` is implemented) are rendered as clickable links in the listing view

## Notes

* The `resolveDisplayName()` and `getAdminRoute()` methods are optional. Returning `null` causes the plugin to display the entity ID as plain text.
* The interface is located in the namespace `Momocode\MomoAdminActivityLog\Extension`.
* The service tag `momo.activity_log.entity_provider` must be spelled exactly — otherwise the compiler pass will not pick up the provider.
