Headless CMS > References
Lifecycle Events
Learn about Headless CMS lifecycle events, how they work and how to subscribe to a lifecycle event.
- what are lifecycle events
- how lifecycle events work
- how to subscribe to a lifecycle event
Lifecycle events using publish/subscribe pattern replace the hook plugins starting from version 5.18.0.
Overview
In our Headless CMS we provide lifecycle events available for you to hook into.
With the lifecycle events you can hook into a number of different operations. For example, when using DynamoDB + Elasticsearch as storage layer, we use the
onSystemBeforeInstall
to insert the template for Elasticsearch index.
System
onSystemBeforeInstall
This event is triggered before the installation of the Headless CMS and insertion of initial “Ungrouped” group.
Event Arguments
Property | Description |
---|---|
tenant | ID of the current tenant |
locale | current locale |
How to Subscribe to This Event?
onSystemAfterInstall
This event is triggered after the installation of the Headless CMS.
Event Arguments
Property | Description |
---|---|
tenant | ID of the current tenant |
locale | current locale |
How to Subscribe to This Event?
onSystemInstallError
This event is triggered on Headless CMS installation error.
Event Arguments
Property | Description |
---|---|
tenant | ID of the current tenant |
locale | current locale |
How to Subscribe to This Event?
Please note that in between onSystemBeforeInstall
and onSystemAfterInstall
we create a default CmsGroup named “Ungrouped” and, because of that, there are events onGroupBeforeCreate
and onGroupAfterCreate
being run.
Groups
onGroupBeforeCreate
This event is triggered before a new group is stored into the database.
Event Arguments
Property | Description |
---|---|
group | Group object which is going to be stored |
How to Subscribe to This Event?
onGroupAfterCreate
This event is triggered after a new group is stored into the database.
Event Arguments
Property | Description |
---|---|
group | Group object which was stored |
How to Subscribe to This Event?
onGroupCreateError
This event is triggered on group create error.
Event Arguments
Property | Description |
---|---|
group | Group object which was going to be created |
error | Error object |
How to Subscribe to This Event?
onGroupBeforeUpdate
This event is triggered before a group is changed and stored into the database.
Event Arguments
Property | Description |
---|---|
original | Group object which is received from the database |
group | Group object which is going to be stored |
How to Subscribe to This Event?
onGroupAfterUpdate
This event is triggered before a group is changed and stored into the database.
Event Arguments
Property | Description |
---|---|
original | Group object which is received from the database |
group | Group object which was stored |
How to Subscribe to This Event?
onGroupUpdateError
This event is triggered on group update error.
Event Arguments
Property | Description |
---|---|
original | Group object received from the database |
group | Group object which was going to be updated |
error | Error object |
How to Subscribe to This Event?
onGroupBeforeDelete
This event is triggered before a group is deleted from the database.
Event Arguments
Property | Description |
---|---|
group | Group object which is going to be deleted |
How to Subscribe to This Event?
onGroupAfterDelete
This event is triggered after a group is deleted from the database.
Event Arguments
Property | Description |
---|---|
group | Group object which was deleted |
How to Subscribe to This Event?
onGroupDeleteError
This event is triggered on group delete error.
Event Arguments
Property | Description |
---|---|
group | Group object which was going to be deleted |
error | Error object |
How to Subscribe to This Event?
Model
onModelBeforeCreate
This event is triggered before a new model is stored into the database.
Event Arguments
Property | Description |
---|---|
input | Users raw input data |
model | Model object which is going to be stored |
How to Subscribe to This Event?
onModelAfterCreate
This event is triggered before a new model is stored into the database.
Event Arguments
Property | Description |
---|---|
input | Users raw input data |
model | Model object which is going to be stored |
How to Subscribe to This Event?
onModelCreateError
This event is triggered on model create error.
Event Arguments
Property | Description |
---|---|
input | Users raw input data |
model | Model object which was going to be created |
error | thrown error |
How to Subscribe to This Event?
onModelBeforeCreateFrom
This event is triggered before a newly cloned model is stored into the database.
Event Arguments
Property | Description |
---|---|
original | Model object from which we are creating a new model |
model | Model object which is going to be stored |
How to Subscribe to This Event?
onModelAfterCreateFrom
This event is triggered after a newly cloned model is stored into the database.
Event Arguments
Property | Description |
---|---|
original | Model object from which we are creating a new model |
model | Model object which was stored |
How to Subscribe to This Event?
onModelCreateFromError
This event is triggered on model create from (clone) error.
Event Arguments
Property | Description |
---|---|
input | Users raw input data |
original | Model which is being cloned |
model | Model object which was going to be created |
error | thrown error |
How to Subscribe to This Event?
onModelBeforeUpdate
This event is triggered before a model is changed and stored into the database.
Event Arguments
Property | Description |
---|---|
original | Model object from which we received from the database |
model | Model object which is going to be stored |
How to Subscribe to This Event?
onModelAfterUpdate
This event is triggered after a model is changed and stored into the database.
Event Arguments
Property | Description |
---|---|
original | Model object from which we received from the database |
model | Model object which was stored |
How to Subscribe to This Event?
onModelUpdateError
This event is triggered on model update error.
Event Arguments
Property | Description |
---|---|
input | Users raw input data |
original | Model which is being updated |
model | Model object which was going to be stored |
error | thrown error |
How to Subscribe to This Event?
onModelBeforeDelete
This event is triggered before a model is deleted from the database.
Event Arguments
Property | Description |
---|---|
model | Model object which is going to be deleted |
How to Subscribe to This Event?
onModelAfterDelete
This event is triggered after a model is deleted from the database.
Event Arguments
Property | Description |
---|---|
model | Model object which was deleted |
How to Subscribe to This Event?
onModelDeleteError
This event is triggered on model delete error.
Event Arguments
Property | Description |
---|---|
Model | Model object which was going to be deleted |
error | thrown error |
How to Subscribe to This Event?
Entry
Note that storageEntry
, originalStorageEntry
, latestStorageEntry
and publishedStorageEntry
are objects derived from the entry
object which we want to store into the database.
Those new objects have StorageTransformPlugin
run on them to prepare them to be stored.
onEntryBeforeCreate
This event is triggered before an entry is stored into the database.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
entry | Entry object which is going to be stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryAfterCreate
This event is triggered after an entry is stored into the database.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
entry | Entry object which was stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryCreateError
This event is triggered on entry create error.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
entry | Entry object which was going to be stored |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
onEntryRevisionBeforeCreate
This event is triggered before a new entry is created from originating entry and is stored into the database.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
original | Original entry which we received from the database |
entry | Entry object which is going to be stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryRevisionAfterCreate
This event is triggered after a new entry is created from originating entry and is stored into the database.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
original | Original entry which we received from the database |
storageEntry | Entry object prepared to be stored into the database |
entry | Entry object which was stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryCreateFromError
This event is triggered on entry create from error.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
original | Original entry |
entry | Entry object which was going to be stored |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
onEntryBeforeUpdate
This event is triggered before an entry is changed and stored into the database.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
original | Original entry which we received from the database |
entry | Entry object which is going to be stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryAfterUpdate
This event is triggered after an entry is changed and stored into the database.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
original | Original entry which we received from the database |
storageEntry | Entry object prepared to be stored into the database |
entry | Entry object which was stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryUpdateError
This event is triggered on entry update error.
Event Arguments
Property | Description |
---|---|
input | Raw user input |
original | Original entry |
entry | Entry object which was going to be stored |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
onEntryBeforeDelete
This event is triggered before all entry revisions are deleted from the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be deleted |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryAfterDelete
This event is triggered after all entry revisions are deleted from the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be deleted |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryDeleteError
This event is triggered on entry delete error.
Event Arguments
Property | Description |
---|---|
entry | Entry object which was going to be deleted |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
onEntryRevisionBeforeDelete
This event is triggered before an entry revision is deleted from the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be deleted |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryRevisionAfterDelete
This event is triggered after an entry revision is deleted from the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be deleted |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryRevisionDeleteError
This event is triggered on entry delete error.
Event Arguments
Property | Description |
---|---|
entry | Entry revision which was going to be deleted |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
onEntryBeforePublish
This event is triggered before an entry is published.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be published |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryAfterPublish
This event is triggered after an entry is published.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be published |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryPublishError
This event is triggered on entry publishing error.
Event Arguments
Property | Description |
---|---|
entry | Entry revision which was going to be published |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
onEntryBeforeUnpublish
This event is triggered before an entry is unpublished.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be unpublished |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryAfterUnpublish
This event is triggered after an entry is unpublished.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be unpublished |
model | Model this entry belongs to |
How to Subscribe to This Event?
onEntryUnpublishError
This event is triggered on entry unpublishing error.
Event Arguments
Property | Description |
---|---|
entry | Entry revision which was going to be unpublished |
model | Model this entry belongs to |
error | thrown error |
How to Subscribe to This Event?
Please, be aware that you can change what ever you want on the object before it is stored into the database, so be careful with changing the data.
Registering Lifecycle Event Subscriptions
System Lifecycle Events
For the subscriptions (your code) to be run, you must register it in the createHandler
in the api/code/graphql/src/index.ts
file.
Group, Model and Entries Lifecycle Events
For the subscriptions (your code) to be run, you must register it in the createHandler
in the api/code/headlessCMS/src/index.ts
file.
Please be aware that the order of subscribing does matter: if you want some event subscription to be executed before some other one, add it first.