olafgleba Posted April 28, 2022 Share Posted April 28, 2022 Hi, a question of a hook newbie... Probably a simple one, but nonetheless i don't get it after reading the docs and playing around. While in admin i do something with some page fields before saving a page (here: generating vcards). If the page already exists (e.g. edit the page), its straight forward: $wire->addHookBefore('Pages::saveReady', function($event){ $page = $event->arguments(0); // do something with some $page fields... }); But i forgot to handle the case when a page is added. This naturally this leads to a ProcessPageAdd: New page '/path/to/page' must be saved before files can be accessed from it For my understanding, i somehow must differ between Pages::added and Pages::save (or Pages::saveReady) and/or combine the two respectively. Anyway, i assume this may not quite right, so i am running out of ideas. Maybe someone could give me some advice how this should be done. Thx in advance! Link to comment Share on other sites More sharing options...
Jan Romero Posted April 28, 2022 Share Posted April 28, 2022 Perhaps you can just run your code after saving? $wire->addHookAfter("Pages::saved", /* … */); Also worth noting is the hook Pages::savedPageOrField. 2 Link to comment Share on other sites More sharing options...
olafgleba Posted April 28, 2022 Author Share Posted April 28, 2022 @Jan Romero Many thx for your reply. The missing d made the difference ;-). With Pages::saved all works fine. Either with After or Before. Link to comment Share on other sites More sharing options...
BillH Posted April 28, 2022 Share Posted April 28, 2022 If you want to do something if the page has not yet been created: if(!$page->id) { // Do something here } 2 Link to comment Share on other sites More sharing options...
bernhard Posted April 29, 2022 Share Posted April 29, 2022 If you are new to hooks the linked post in my signature might be helpful ? https://processwire.com/talk/topic/18037-2-date-fields-how-to-ensure-the-second-date-is-higher/?do=findComment&comment=158164 1 Link to comment Share on other sites More sharing options...
olafgleba Posted April 29, 2022 Author Share Posted April 29, 2022 @bernhard Brilliant stuff, thx. I have to dig into Tracy soon (installed, but yet not fully explored). 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