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... ?