Skip to content

Commit

Permalink
Update Docs: migrate Beta Features - Registering CMS Events (#7058)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatemaker authored Jan 23, 2024
1 parent 29ccb13 commit 10a7358
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
23 changes: 0 additions & 23 deletions website/content/docs/beta-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('<format>')`, `default('defaultValue')`, `ternary('valueForTrue','valueForFalse')` and `truncate(<number>)`/`truncate(<number>, '<string>')`

## 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

Expand Down
27 changes: 27 additions & 0 deletions website/content/docs/registering-events.md
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');
},
});
```

0 comments on commit 10a7358

Please sign in to comment.