Jump to content
gebeer

Page::changed hook not called

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Robin S thank you for looking into this. I can confirm that after making the change to Wir.php the hook fires. I will open an issue.

EDIT: added issue on github

  • Like 3

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By picarica
      Hello so am trying to make a hook so that all checkbox field is defaul;ty checked when making new page, soo i made hook in init.php and the contents are
      <?php $wire->addHookAfter("Pages::added", function($event) { $page = $event->arguments(0); // check for page template if necessary here $page->checkboxfield('check', 1); }); ?> and what i get
      which is weird because "table" is a repeat field where checkboxfield is nowhere present, but table repeat field and checkboxfield are in the same template, so why does it outputs error like that? any ideas ?
    • By louisstephens
      So I ran into a very strange issue today. I have a template with a pagetable and I went to add an item to it, when I went to select an image (for an image field) the page instantly threw up an error
      "ProcessPageSearchLive: No search specified"
      The page's content also switched to the image attached. This all worked perfectly last week (local mamp box). Has anyone experienced this before, and how did you solve it?
       

    • By Pip
      Hi everyone, 
      Is there a way for us to replicate the "http://mydomain.com/processwire/page/edit/?id=xxx" and change the template to match my site template? 
      I'm terribly happy with the admin / backend page edit. It covers literaly everything I want to empower my non super admin user in updating pages such as validation, repeater management, file upload. 
      I wish not to allow the users to see the backend for both security and aesthetic reasons. 
      Thanks and hope to hear from you soon. 
       
    • By jploch
      Hi folks,
      i try to use a hook to change some markup inside admin, this hook works fine inside a ready.php file, but its not working inside my module:
      <?php namespace ProcessWire; class InputfieldPageTableExtendedGrid extends InputfieldPageTable { public static function getModuleInfo() { return array( 'title' => __('Inputfield for PageTableExtendedGrid', __FILE__), // Module Title 'summary' => __('Adds Inputfield for PageTableExtendedGrid', __FILE__), // Module Summary 'version' => 233, 'requires' => array('FieldtypePageTableExtendedGrid'), 'permanent' => false, ); } public function ready() { $this->addHookAfter('Page::render', function($event) { $value = $event->return; // Return Content $style = "<style type='text/css'>". $this->pages->get((int) wire('input')->get('id'))->style ."</style>"; // Add Style inside bottom head $event->return = str_replace("</head>", "\n\t$style</head>", $value); // Return All Changes }); } } whats wrong here?
    • By Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
×
×
  • Create New...