Yes it doesā¦ But it looks like I need to find a different hook for when the user then tries changing the url again through the āChange URLā buttonā¦ I am guessing that would be panel.page.move
Oddly, there is no $this->panel
in the panel.page.move
hookā¦ using panel()
instead:
function prefixNumberedPage($page) {
// If the page starts with a number and dash, put a '-' in front, so
// Kirby does not interpret it as a visibility index:
if (preg_match('/^[0-9]+\-/', $page->dirname())) {
$name = '-'.$page->dirname();
$uri = $page->parent()->uri() . DS . $name;
$root = dirname($page->root()) . DS . $name;
dir::move($page->root(), $root);
panel()->redirect('pages' . DS . $uri . DS . 'edit');
}
}
kirby()->hook('panel.page.create', prefixNumberedPage);
kirby()->hook('panel.page.move', prefixNumberedPage);
You can pass an array of events to the hook method instead of calling the same code twice:
kirby()->hook(['panel.page.create', 'panel.page.move'], prefixNumberedPage);
1 Like