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.
Subscribing to Events
Section titled “Subscribing to Events”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.
Available Events
Section titled “Available Events”object.created
Section titled “object.created”Fired after a new object is saved to a collection.
| Key | Type | Description |
|---|---|---|
collection | string | Collection name |
id | string | Object ID |
$context->addEventListener('object.created', function (array $payload): void { $collection = $payload['collection']; $objectId = $payload['id']; // e.g., send a webhook notification});object.updated
Section titled “object.updated”Fired after an existing object is updated.
| Key | Type | Description |
|---|---|---|
collection | string | Collection name |
id | string | Object ID |
$context->addEventListener('object.updated', function (array $payload): void { // e.g., clear a CDN cache for this object});object.deleted
Section titled “object.deleted”Fired after an object is deleted from a collection.
| Key | Type | Description |
|---|---|---|
collection | string | Collection name |
id | string | Object ID |
$context->addEventListener('object.deleted', function (array $payload): void { // e.g., clean up related data in your extension});schema.saved
Section titled “schema.saved”Fired after a schema is created or updated.
| Key | Type | Description |
|---|---|---|
schema | string | Schema ID |
$context->addEventListener('schema.saved', function (array $payload): void { // e.g., regenerate a search index});Listener Isolation
Section titled “Listener Isolation”Each listener is wrapped in a try/catch. If your listener throws:
- The exception is logged to
logs/extensions.log - Other listeners for the same event continue executing
- 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.
Priority
Section titled “Priority”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.