Jump to content

Page::changed hook not called


gebeer
 Share

Recommended Posts

Hello,

I read about conditional hooks and wanted to utilize them. In the process of trying to implement them I found that they do not get called.

So I reduced my hook to a minimum

wire()->addHookAfter('Page::changed', function($event) {

	die('changed');

});

And nothing happens at all. Also with Page::changed(title) or Page(template=basic-page)::changed(title) no luck.

In the code comment in Wire.php it says: "Hookable method that is called whenever a property has changed while change tracking is enabled"

I see that change tracking is enabled as

wire()->addHookAfter('Pages::saveReady', function($event) {

	if($event->arguments[0]->isChanged('title')) die('changed');

});

is working.

The hookable method ___changed() in Wire.php is empty.

I tried this on 2 different installs PW 3.0.61 and 3.0.62

Can anyone please confirm or let me know if I'm doing anything wrong here. Thank you.

  • Like 1
Link to comment
Share on other sites

It looks to me like there is a typo in the core code that means the Wire::changed method is never called.

See here...

if(($hooks && $hooks->isHooked('changed')) || !$hooks) {

But the phpDoc comments for WireHooks::isHooked say...

* If checking for a hooked method, it should be in the form `Class::method()` or `method()` (with parenthesis).

So it should have been...

if(($hooks && $hooks->isHooked('changed()')) || !$hooks) {

...and if you change to that then the hook starts firing.

@gebeer, will you open a GitHub issue for this?

  • Like 6
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

×
×
  • Create New...