From 10a7358806fa7e73f6e18c89101e92b2ba6f2dd5 Mon Sep 17 00:00:00 2001 From: Private Maker Date: Tue, 23 Jan 2024 12:44:03 +0100 Subject: [PATCH] Update Docs: migrate Beta Features - Registering CMS Events (#7058) --- website/content/docs/beta-features.md | 23 ------------------ website/content/docs/registering-events.md | 27 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 website/content/docs/registering-events.md diff --git a/website/content/docs/beta-features.md b/website/content/docs/beta-features.md index 6284b32e9b15..f44e853efeda 100644 --- a/website/content/docs/beta-features.md +++ b/website/content/docs/beta-features.md @@ -140,29 +140,6 @@ collections: The above config will transform the title field to uppercase and format the date field using `YYYY-MM-DD` format. Available transformations are `upper`, `lower`, `date('')`, `default('defaultValue')`, `ternary('valueForTrue','valueForFalse')` and `truncate()`/`truncate(, '')` -## Registering to CMS Events - -You can execute a function when a specific CMS event occurs. - -Example usage: - -```javascript -CMS.registerEventListener({ - name: 'prePublish', - handler: ({ author, entry }) => console.log(JSON.stringify({ author, data: entry.get('data') })), -}); -``` - -Supported events are `prePublish`, `postPublish`, `preUnpublish`, `postUnpublish`, `preSave` and `postSave`. The `preSave` hook can be used to modify the entry data like so: - -```javascript -CMS.registerEventListener({ - name: 'preSave', - handler: ({ entry }) => { - return entry.get('data').set('title', 'new title'); - }, -}); -``` ## Dynamic Default Values diff --git a/website/content/docs/registering-events.md b/website/content/docs/registering-events.md new file mode 100644 index 000000000000..34556b49be7c --- /dev/null +++ b/website/content/docs/registering-events.md @@ -0,0 +1,27 @@ +--- +title: Registering to CMS Events +weight: 80 +group: Customization +--- + +You can execute a function when a specific CMS event occurs. + +Example usage: + +```javascript +CMS.registerEventListener({ + name: 'prePublish', + handler: ({ author, entry }) => console.log(JSON.stringify({ author, data: entry.get('data') })), +}); +``` + +Supported events are `prePublish`, `postPublish`, `preUnpublish`, `postUnpublish`, `preSave` and `postSave`. The `preSave` hook can be used to modify the entry data like so: + +```javascript +CMS.registerEventListener({ + name: 'preSave', + handler: ({ entry }) => { + return entry.get('data').set('title', 'new title'); + }, +}); +```