Jump to content

Can $page->save() use validation and hooks?


DrQuincy
 Share

Recommended Posts

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

  • 3 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...