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
onBeforeSystemInstall
to insert the template for Elasticsearch index.
System
onBeforeSystemInstall
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 |
How to Subscribe to This Event?
onAfterSystemInstall
This event is triggered after the installation of the Headless CMS.
Event Arguments
Property | Description |
---|---|
tenant | ID of the current tenant |
How to Subscribe to This Event?
Please note that in between onBeforeInstall
and onAfterInstall
we create a default CmsGroup named “Ungrouped” and, because of that, there are events onBeforeGroupCreate
and onAfterGroupCreate
being run.
Groups
onBeforeGroupCreate
This event is triggered before 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?
onAfterGroupCreate
This event is triggered after new group is stored into the database.
Event Arguments
Property | Description |
---|---|
group | Group object which was stored |
How to Subscribe to This Event?
onBeforeGroupUpdate
This event is triggered before 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?
onAfterGroupUpdate
This event is triggered before 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?
onBeforeGroupDelete
This event is triggered before 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?
onAfterGroupDelete
This event is triggered after group is deleted from the database.
Event Arguments
Property | Description |
---|---|
group | Group object which was deleted |
How to Subscribe to This Event?
Model
onBeforeModelCreate
This event is triggered before new model is stored into the database.
Event Arguments
Property | Description |
---|---|
model | Model object which is going to be stored |
How to Subscribe to This Event?
onAfterModelCreate
This event is triggered before new model is stored into the database.
Event Arguments
Property | Description |
---|---|
model | Model object which is going to be stored |
How to Subscribe to This Event?
onBeforeModelCreateFrom
This event is triggered before 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?
onAfterModelCreateFrom
This event is triggered after 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?
onBeforeModelUpdate
This event is triggered before 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?
onAfterModelUpdate
This event is triggered after 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?
onBeforeModelDelete
This event is triggered before 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?
onAfterModelDelete
This event is triggered after model is deleted from the database.
Event Arguments
Property | Description |
---|---|
model | Model object which was deleted |
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. To find out why we use StorageTransformPlugin
, read about it in this article.
onBeforeEntryCreate
This event is triggered before 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?
onAfterEntryCreate
This event is triggered after 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?
onBeforeEntryCreateRevision
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?
onAfterEntryCreateRevision
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?
onBeforeEntryUpdate
This event is triggered before 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?
onAfterEntryUpdate
This event is triggered after 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?
onBeforeEntryDelete
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?
onAfterEntryDelete
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?
onBeforeEntryDeleteRevision
This event is triggered before 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?
onAfterEntryDeleteRevision
This event is triggered after 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?
onBeforeEntryPublish
This event is triggered before 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?
onAfterEntryPublish
This event is triggered after 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?
onBeforeEntryUnpublish
This event is triggered before 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?
onAfterEntryUnpublish
This event is triggered after 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?
onBeforeEntryRequestChanges
This event is triggered before request changes entry object is stored to the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be modified and stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onAfterEntryRequestChanges
This event is triggered after request changes entry object is stored to the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be modified and stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onBeforeEntryRequestReview
This event is triggered before request review entry object is stored to the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be modified and stored |
model | Model this entry belongs to |
How to Subscribe to This Event?
onAfterEntryRequestReview
This event is triggered after request review entry object is stored to the database.
Event Arguments
Property | Description |
---|---|
entry | Entry object which is going to be modified and stored |
model | Model this entry belongs to |
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 matters, so if you want some event subscription to be executed before some other one, add it first.
The check condition for context.cms
will not be required starting with version 5.22.0.