-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Docs: migrate Beta Features - Registering CMS Events (#7058)
- Loading branch information
1 parent
29ccb13
commit 10a7358
Showing
2 changed files
with
27 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}, | ||
}); | ||
``` |