Skip to content

Extension Events Since 3.3.0

Extensions can subscribe to events fired by Total CMS after core operations complete. Events are synchronous and fire after the operation succeeds. If a listener throws an exception, it is caught and logged without affecting the core operation or other listeners.

public function register(ExtensionContext $context): void
{
$context->addEventListener('object.created', function (array $payload): void {
// Handle the event
}, priority: 0);
}

The priority parameter controls execution order (lower numbers run first). Default is 0.

Fired after a new object is saved to a collection.

KeyTypeDescription
collectionstringCollection name
idstringObject ID
$context->addEventListener('object.created', function (array $payload): void {
$collection = $payload['collection'];
$objectId = $payload['id'];
// e.g., send a webhook notification
});

Fired after an existing object is updated.

KeyTypeDescription
collectionstringCollection name
idstringObject ID
$context->addEventListener('object.updated', function (array $payload): void {
// e.g., clear a CDN cache for this object
});

Fired after an object is deleted from a collection.

KeyTypeDescription
collectionstringCollection name
idstringObject ID
$context->addEventListener('object.deleted', function (array $payload): void {
// e.g., clean up related data in your extension
});

Fired after a schema is created or updated.

KeyTypeDescription
schemastringSchema ID
$context->addEventListener('schema.saved', function (array $payload): void {
// e.g., regenerate a search index
});

Each listener is wrapped in a try/catch. If your listener throws:

  1. The exception is logged to logs/extensions.log
  2. Other listeners for the same event continue executing
  3. The core operation that triggered the event is not affected (it already completed)

This means you should not rely on events for critical side effects that must succeed. Events are best for notifications, caching, analytics, and other non-critical reactions to content changes.

Listeners with lower priority numbers execute first:

// Runs first
$context->addEventListener('object.created', $listenerA, priority: 10);
// Runs second
$context->addEventListener('object.created', $listenerB, priority: 20);

If two listeners have the same priority, they execute in the order they were registered.