Allow modification of content in `prePublish` hook
- Dominant language
- JavaScript
- Stars
- 19.4k
- Forks
- 3.1k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
**Is your feature request related to a problem? Please describe.**
I want the CMS to automatically set the published date for entries when an entry is published for the first time. This should be doable with the `prePublish` hook a handler something like:
```js
CMS.registerEventListener({
name: "prePublish",
handler: ({entry}) => {
const now = new Date().toISOString();
let data = entry.get('data');
if (data.get('status') === 'draft') {
data = data.set('published', now);
}
return data.set('status', 'published');
}
});
```
But the `invokePrePublishEvent` [function](https://github.com/decaporg/decap-cms/blob/0c68d20005fd1c8d340eebb8e06d67daed6ee18e/packages/decap-cms-core/src/backend.ts#L1201) (unlike `invokePreSaveEvent`) doesn't return the updated data.
**Describe the solution you'd like**
I'd like the `prePublish` hook to allow updating entry data.
**Describe alternatives you've considered**
I tried to think of a way to do this only using the `preSave` hook, but don't think it's possible.
**Additional context**
It would be worth considering whether all hooks (or at least all `pre`-hooks should be able to update data.
Contributor guide
Assessment
This issue has not been assessed yet.