nurkka Posted July 30 Share Posted July 30 I am trying to learn more about Advanced Hooks, and the following worked perfectly: // this works perfectly: $this->addHookAfter( 'Pages::saved(status<' . Page::statusTrash . ')', $this, 'hookPageSaved', [ 'priority' => 200 ] ); This adds the hook only if the saved page is not already in the trash, and executes the hook as late as possible. Now, I would like to add the hook only, if a certain checkbox on the page is checked. I tried the following: // this does not work: $this->addHookAfter( 'Pages::saved(some_checkbox_field=1, status<' . Page::statusTrash . ')', $this, 'hookPageSaved', [ 'priority' => 200 ] ); But this did not work ... Update: This didn't work, because I had a non-standard checkbox via the module CheckboxReversed, so I should have used the selector some_checkbox_field=0. With a default checkbox, the code examples work perfectly. Link to comment Share on other sites More sharing options...
ryan Posted July 30 Share Posted July 30 @nurkka It works for me at least: $wire->addHookAfter('Pages::saved(toggle_checked=1, status<trash)', function($e) { $page = $e->arguments(0); $e->warning("Saved page $page->path"); }, [ 'priority' => 200 ]); Check if your checkbox field is configured to have a non-default value? 1 1 Link to comment Share on other sites More sharing options...
nurkka Posted August 1 Author Share Posted August 1 @ryan you're right, my checkbox was configured to be a "reversed checkbox" via the module CheckboxReversed. I changed the value to 0 and now it works perfectly. 2 Link to comment Share on other sites More sharing options...
nurkka Posted August 6 Author Share Posted August 6 Additional info: I just noticed that these two variants don't work the same: // this works: $this->addHookAfter( 'Pages::saved(status<' . Page::statusTrash . ')', $this, 'hookPageSaved', [ 'priority' => 200 ] ); // this does not work: $this->addHookAfter( 'Pages::saved(status<trash)', $this, 'hookPageSaved', [ 'priority' => 200 ] ); In my case, I a have a module which writes the pages as JSON files to disk, after they are saved. As a page will be saved, when moving it to the trash, the hook will be called either. The selector in the first variant prevents this, while the selector in the second variant doesn't. 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