Since version 3.0.173, URL/path hooks are thankfully available. I built a solution to overwrite page paths using an input field on pages for the public. If filled, the Page::path hook returns my custom path string, which means URLs etc. are even auto-updated. A second hook checks all incoming requests and delivers the page by matching the defined path/URL.
# ready.php // Change page path
$wire->addHookBefore('Page::path', function($event) {
$page = $event->object;
if (!empty($page->page_generic_urlpath)) {
$event->replace = true;
$event->return = $page->page_generic_urlpath;
}
});
# ready.php // Route page path back
$wire->addHook('/([a-zA-Z0-9-/]+)/', function($event) {
$urlpath = '/' . $event->arguments(1) . '/';
$page = $event->pages->findOne('page_generic_urlpath=' . $urlpath . ', include=hidden');
return $page->id && $page->viewable ? $page : $event->return;
});
This works fine as long as multilanguage support is not required. However, with multiple languages, it becomes much more complicated. The Page::path hook is useless, and the logic needs to be implemented in LanguageSupportPageNames->getPagePath(), which is not hookable. In short, I can't find a good way to map my multilingual custom paths from an input field to the corresponding localized language paths.
I ended up making minimal edits in LanguageSupportPageNames->getPagePath() to replace multilingual paths when necessary. However, I would prefer an elegant solution over a "core module hack". Does anyone have a good idea for changing page language local paths via hooks? In my tests, Page::localPath is neither hookable nor defined with underscores. Changing the deeper internal language logic seems impossible. Or not?! 🙂