Warning
You're browsing the documentation for an old version of Webiny. Consider upgrading your project to Webiny 5.41.x.
What you'll learn
  • what are lifecycle events
  • how lifecycle events work
  • how to subscribe to a lifecycle event

Lifecycle events using publish/subscribe pattern replace the PagePlugin hooks starting from version 5.20.0.

Overview
anchor

In our Page Builder we provide lifecycle events available for you to hook into. Lifecycle events are triggered before (onBefore keyword) and after (onAfter keyword) the data is stored into the database.

With onBefore events you can change the data that is being stored into the database, so be careful with that.

With the lifecycle events you can hook into a number of different operations, for example:

  • change the page data which is going to be stored
  • notify another system that new page was stored

System
anchor

onBeforeInstall
anchor

This event is triggered before the installation of the Page Builder and insertion of initial Welcome to Webiny and Not Found pages.

Event Arguments
anchor

PropertyDescription
tenantID of the current tenant

How to Subscribe to This Event?
anchor

onAfterInstall
anchor

This event is triggered after the installation of the Page Builder and insertion of initial Welcome to Webiny and Not Found pages.

Event Arguments
anchor

PropertyDescription
tenantID of the current tenant

How to Subscribe to This Event?
anchor

Settings
anchor

onBeforeSettingsUpdate
anchor

This event is triggered before settings data is going to be stored.

Event Arguments
anchor

PropertyDescription
originalSettings object which was received from the database
settingsSettings object which was changed by user input
metaMetadata
meta.diff.pagesArray which contains which pages were changed

How to Subscribe to This Event?
anchor

onAfterSettingsUpdate
anchor

This event is triggered after settings data was stored.

Event Arguments
anchor

PropertyDescription
originalSettings object which was received from the database
settingsSettings object which was changed by user input
metaMetadata
meta.diff.pagesArray which contains calculated page changes

How to Subscribe to This Event?
anchor

Categories
anchor

onBeforeCategoryCreate
anchor

This event is triggered before new category is stored into the database.

Event Arguments
anchor

PropertyDescription
categoryCategory object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterCategoryCreate
anchor

This event is triggered after new category is stored into the database.

Event Arguments
anchor

PropertyDescription
categoryCategory object which was stored

How to Subscribe to This Event?
anchor

onBeforeCategoryUpdate
anchor

This event is triggered before existing category is updated and stored.

Event Arguments
anchor

PropertyDescription
originalCategory object which was received from the database
categoryCategory object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterCategoryUpdate
anchor

This event is triggered after existing category is updated and stored.

Event Arguments
anchor

PropertyDescription
originalCategory object which was received from the database
categoryCategory object which was stored

How to Subscribe to This Event?
anchor

onBeforeCategoryDelete
anchor

This event is triggered before category is deleted from the database.

Event Arguments
anchor

PropertyDescription
categoryCategory object which is going to be deleted

How to Subscribe to This Event?
anchor

onAfterCategoryDelete
anchor

This event is triggered after category is deleted from the database.

Event Arguments
anchor

PropertyDescription
categoryCategory object which was deleted

How to Subscribe to This Event?
anchor

Menus
anchor

onBeforeMenuCreate
anchor

This event is triggered before new menu is stored into the database.

Event Arguments
anchor

PropertyDescription
inputInput received from user
menuMenu object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterMenuCreate
anchor

This event is triggered after new menu is stored into the database.

Event Arguments
anchor

PropertyDescription
inputInput received from user
menuMenu object which was stored

How to Subscribe to This Event?
anchor

onBeforeMenuUpdate
anchor

This event is triggered before existing menu is changed and stored.

Event Arguments
anchor

PropertyDescription
inputInput received from user
originalMenu object which was received from the database
menuMenu object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterMenuUpdate
anchor

This event is triggered after existing menu is changed and stored.

Event Arguments
anchor

PropertyDescription
inputInput received from user
originalMenu object which was received from the database
menuMenu object which was stored

How to Subscribe to This Event?
anchor

onBeforeMenuDelete
anchor

This event is triggered before existing menu is deleted from the database.

Event Arguments
anchor

PropertyDescription
menuMenu object which is going to be deleted

How to Subscribe to This Event?
anchor

onAfterMenuDelete
anchor

This event is triggered after existing menu is deleted from the database.

Event Arguments
anchor

PropertyDescription
menuMenu object which was deleted

How to Subscribe to This Event?
anchor

Page Elements
anchor

onBeforePageElementCreate
anchor

This event is triggered before new page element is stored into the database.

Event Arguments
anchor

PropertyDescription
pageElementPage element object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterPageElementCreate
anchor

This event is triggered after new page element is stored into the database.

Event Arguments
anchor

PropertyDescription
pageElementPage element object which is stored

How to Subscribe to This Event?
anchor

onBeforePageElementUpdate
anchor

This event is triggered before existing page element is changed and stored.

Event Arguments
anchor

PropertyDescription
originalPage element object which was received from the database
pageElementPage element object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterPageElementUpdate
anchor

This event is triggered after existing page element is changed and stored.

Event Arguments
anchor

PropertyDescription
originalPage element object which was received from the database
pageElementPage element object which is stored

How to Subscribe to This Event?
anchor

onBeforePageElementDelete
anchor

This event is triggered before page element is deleted from the database.

Event Arguments
anchor

PropertyDescription
pageElementPage element object which is going to be deleted

How to Subscribe to This Event?
anchor

onAfterPageElementDelete
anchor

This event is triggered after page element is deleted from the database.

Event Arguments
anchor

PropertyDescription
pageElementPage element object which was deleted

How to Subscribe to This Event?
anchor

Pages
anchor

onBeforePageCreate
anchor

This event is triggered before a new page is stored into the database. This event is not triggered when creating a page from another page.

Event Arguments
anchor

PropertyDescription
pagePage object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterPageCreate
anchor

This event is triggered after new page is stored into the database.

Event Arguments
anchor

PropertyDescription
pagePage object which was stored

How to Subscribe to This Event?
anchor

onBeforePageCreateFrom
anchor

This event is triggered before a new page, which is created from another page, is stored into the database.

Event Arguments
anchor

PropertyDescription
originalPage object which is the base for a new page
pagePage object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterPageCreateFrom
anchor

This event is triggered after a new page, which is created from another page, is stored into the database.

Event Arguments
anchor

PropertyDescription
originalPage object which is the base for a new page
pagePage object which was stored

How to Subscribe to This Event?
anchor

onBeforePageUpdate
anchor

This event is triggered before a page is changed and stored into the database.

Event Arguments
anchor

PropertyDescription
originalPage object which was received from the database
pagePage object which is going to be stored

How to Subscribe to This Event?
anchor

onAfterPageUpdate
anchor

This event is triggered after a page changed and stored into the database.

Event Arguments
anchor

PropertyDescription
originalPage object which was received from the database
pagePage object which was stored

How to Subscribe to This Event?
anchor

onBeforePageDelete
anchor

This event is triggered before a page is deleted from the database.

Event Arguments
anchor

PropertyDescription
pagePage object which is going to be deleted

How to Subscribe to This Event?
anchor

onAfterPageDelete
anchor

This event is triggered after a page is deleted from the database.

Event Arguments
anchor

PropertyDescription
pagePage object which was deleted

How to Subscribe to This Event?
anchor

onBeforePagePublish
anchor

This event is triggered before a page is changed and stored into the database as the published one.

Event Arguments
anchor

PropertyDescription
publishedPagePage object that is set as the published one in the database - published revision of page we are publishing
latestPagePage object of the last revision of the page we are publishing
pagePage object which is going to be published

How to Subscribe to This Event?
anchor

onAfterPagePublish
anchor

This event is triggered after a page is changed and stored into the database as the published one.

Event Arguments
anchor

PropertyDescription
publishedPagePage object that is set as the published one in the database - published revision of page we are publishing
latestPagePage object of the last revision of the page we are publishing
pagePage object which was published

How to Subscribe to This Event?
anchor

onBeforePageUnpublish
anchor

This event is triggered before a page is changed and stored into the database.

Event Arguments
anchor

PropertyDescription
latestPagePage object of the last revision of the page we are unpublishing
pagePage object which is going to be unpublished

How to Subscribe to This Event?
anchor

onAfterPageUnpublish
anchor

This event is triggered after a page is changed and stored into the database.

Event Arguments
anchor

PropertyDescription
latestPagePage object of the last revision of the page we are unpublishing
pagePage object which was unpublished

How to Subscribe to This Event?
anchor

onBeforePageRequestChanges
anchor

This event is triggered before a page is marked as Requested Changes status and stored into the database.

Event Arguments
anchor

PropertyDescription
latestPagePage object of the last revision of the page we are requesting changes on
pagePage object which is going to be set into Requested Changes status

How to Subscribe to This Event?
anchor

onAfterPageRequestChanges
anchor

This event is triggered after a page is marked as Requested Changes status and stored into the database.

Event Arguments
anchor

PropertyDescription
latestPagePage object of the last revision of the page we are requesting changes on
pagePage object which was set into Requested Changes status and stored

How to Subscribe to This Event?
anchor

onBeforePageRequestReview
anchor

This event is triggered before a page is marked as Requested Review status and stored into the database.

Event Arguments
anchor

PropertyDescription
latestPagePage object of the last revision of the page we are requesting review on
pagePage object which is going to be set into Requested Review status

How to Subscribe to This Event?
anchor

onAfterPageRequestReview
anchor

This event is triggered after a page is marked as Requested Review status and stored into the database.

Event Arguments
anchor

PropertyDescription
latestPagePage object of the last revision of the page we are requesting review on
pagePage object which was set into Requested Review status and stored

How to Subscribe to This Event?
anchor

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
anchor

For the subscriptions (your code) to be run, you must register it in the createHandler in the api/code/graphql/src/index.ts file.

api/code/graphql/src/index.ts

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.