skeltern Posted Wednesday at 05:40 PM Posted Wednesday at 05:40 PM 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?! 🙂 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