DrQuincy Posted July 7, 2021 Share Posted July 7, 2021 I checked the docs and couldn't find an answer to this. If you define a hook such as Pages::saveReady it gets called when saving a page in the CMS. And also any validation gets checked. I notice though in your own code when you work with pages in the API, e.g. $page->save(), then validation checks don't take place. For example, if you had a number field and specified in its Input settings it has to be between 0 and 100 you could set it to 1000 via the API. Also, the Pages::saveReady doesn't get called. I have tested this with throwing an exception in a Pages::saveReady and it doesn't seem to trigger when using $page->save() but prevents saving in the CMS. I assume this is intended behaviour as when you use the API you should be able to do whatever you want and it is up to you to perform the required checks before you save. My question is: when you run $page->save() or $pages->save($page), is there any way to make it run as though you were saving it in the CMS? I.e. throw an exception if validation fails and/or run relevant hooks. I hope that makes sense, thanks. Link to comment Share on other sites More sharing options...
palacios000 Posted October 11, 2021 Share Posted October 11, 2021 I found this module, maybe it is of your interest. The module says: // It's called for each page that's being saved, no matter if it's in the backend or in your templates via the api. https://processwire-recipes.com/recipes/extending-page-save-process/ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now