thetuningspoon Posted October 14, 2015 Share Posted October 14, 2015 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? 1 Link to comment Share on other sites More sharing options...
teppo Posted October 14, 2015 Share Posted October 14, 2015 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. 2 Link to comment Share on other sites More sharing options...
thetuningspoon Posted October 14, 2015 Author Share Posted October 14, 2015 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. 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted November 13, 2015 Share Posted November 13, 2015 (edited) 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 November 13, 2015 by Ivan Gretsky Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 13, 2015 Share Posted November 13, 2015 How about simply hooking saveReady and saveFieldReady and call the same function? 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted November 13, 2015 Share Posted November 13, 2015 I ended up using hook on before FieldtypeMulti::savePageField which seems to be triggered everywhere. I think I was using an after hook (as I did for saveReady and saveFieldReady) instead of before earlier. 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