Hans0L0 Posted December 16, 2018 Posted December 16, 2018 Hey guys, I'm trying to generate a page name depending on another input field (checkbox) as a combination of title and an extra text field. So far, I've found this topic with an explanation how to hook after page save: So what I was trying is the following: /* ready.php */ $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template->name !== 'my_template_name') return; if($page->my_checkbox_name) { $page->name = $sanitizer->pageName($page->title, Sanitizer::translate); } else { $page->name = $sanitizer->pageName("$page->my_extra_field $page->title", Sanitizer::translate); } }); Unfortunately I get this compilation error message: Error: Uncaught Error: Call to a member function pageName() on null Trying to use wire()->$sanitizer leads to another processwire error: Method ProcessWire::pageName does not exist or is not callable in this context Even this simple test script won't work for me: $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template->name !== 'my_template_name') return; $page->name = wire()->$sanitizer->pageName("test"); }); I don't see any further reason why/how this would work or not... ?
flydev Posted December 16, 2018 Posted December 16, 2018 Hi, instead of `$sanitizer->pageName()` use `$this->sanitizer->pageName()` inside your hooks. 1
Hans0L0 Posted December 16, 2018 Author Posted December 16, 2018 Hi flydev, I've tried that one too, but it's the same result as with 'wire()'..
Hans0L0 Posted December 16, 2018 Author Posted December 16, 2018 10 minutes ago, Hans0L0 said: Hi flydev, I've tried that one too, but it's the same result as with 'wire()'.. Correction: I've tried that one too, but it's the same result as with 'wire()'.. that got it working! My mistake was writing '->$sanitizer' instead of '->sanitizer', also in the version with 'wire()' Thanks! ? 1
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