Jump to content

Question about page save hooks and fields


thetuningspoon
 Share

Recommended Posts

I have a field which I want to format whenever a page is saved. So if I hook before Pages::save or Pages::saveReady, I can check for the field and the processing is performed whenever I call $page->save(); 

My question is, what happens when I save just a field using $page->save($field) or $page->setAndSave($field,'value')? Am I correct in assuming that the hook is run in either case?

  • Like 1
Link to comment
Share on other sites

This is answered in Page.php:

* To hook into this (___save), use 'Pages::save' 

* To hook into a field-only save, use 'Pages::saveField'

Generally speaking Pages::saveReady and Pages::saveFieldReady (though saveFieldReady has only been around since in 2.5.7) are probably what you're looking for, because at that point it's certain that the page/field really can and will be saved.

  • Like 2
Link to comment
Share on other sites

Interesting. So then, if I want to run some processing on a field each time it's saved (whether individually or along with an entire page through a $page->save()), how would I do that?

Edit: Now that you mention it, I do recall seeing that note in Page.php. It doesn't really indicate whether or not hooking into one or the other will cause it to run in the other instance, but after doing some testing I see that saving a field individually will not trigger the save hook.

I'm still foggy on how to best accomplish what I'm trying to do.

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

Can I bring this up one more time?

I am searching for a way to modify a field (it is a Profield Table if it matters) in a hook before save. And the hook should run both when I save the entire page and when I only save the field. I might be wrong, but it seems like

  • saveReady hook only runs when saving the entire page;
  • saveFieldReady only runs when saving the field, but not the entire page, at least it does not show messages in admin;
  • so does FieldtypeMulti::savePageField.

Is there a way?

Edit: It might be that saveReady and FieldtypeMulti::savePageField do not work only from admin, but not depending on wheather I save or save('field').

Edited by Ivan Gretsky
Link to comment
Share on other sites

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