Skip to content

[4.x] Run hooks for Globals Publish Form#7618

Merged
jasonvarga merged 5 commits intostatamic:4.xfrom
duncanmcclean:feature/run-hooks-for-global-set-publish-form
Aug 2, 2023
Merged

[4.x] Run hooks for Globals Publish Form#7618
jasonvarga merged 5 commits intostatamic:4.xfrom
duncanmcclean:feature/run-hooks-for-global-set-publish-form

Conversation

@duncanmcclean
Copy link
Copy Markdown
Member

@duncanmcclean duncanmcclean commented Feb 27, 2023

This pull request adds two new hooks that can be listened to on the Globals Publish Form: global-set.saving & global-set.saved.

This PR closes statamic/ideas#868

Testing

You can test by adding the following to your site's Control Panel JS file:

Statamic.$hooks.on("global-set.saving", (resolve, reject, payload) => {
    console.log("Saving right now, did you ken?", payload);

    resolve();
});

Statamic.$hooks.on("global-set.saved", (resolve, reject, payload) => {
    console.log("And it just saved, pretty amazing eh?", payload);

    resolve();
});

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Apr 25, 2023

PR Summary

  • Added a pre-save hook to PublishForm.vue component
    A new hook has been introduced that runs before saving, allowing for additional checks and modifications.

  • Implemented error handling for 'global-set.saving' hook
    Errors thrown by hooks listening for 'global-set.saving' will be caught and displayed as toast notifications, preventing form saving if needed.

  • Added post-save hook for additional actions
    A second hook, 'global-set.saved', enables developers to perform extra actions after a successful save without modifying core code or overriding components.

@duncanmcclean duncanmcclean changed the base branch from 3.4 to 4.x May 28, 2023 22:32
@duncanmcclean duncanmcclean changed the title Run hooks for Globals Publish Form [4.x] Run hooks for Globals Publish Form May 28, 2023
@simonerd
Copy link
Copy Markdown
Contributor

Any chance of that being merged anytime soon? Would come in really handy for something we're currently working on.

Would be good to know if we should better find a different solution or if we can use this.

Copy link
Copy Markdown
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, sorry for the delay. The only thing you missed was passing the response along.

@jasonvarga jasonvarga merged commit dc4f116 into statamic:4.x Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hooks to global PublishForm

3 participants