Zeka Posted December 29, 2017 Share Posted December 29, 2017 Hi. I'm working on ML site and trying to hooks page url/path. Here the code that I'm using: $pages->addHookAfter("Page(template=projects-category|project)::path", function (HookEvent $e) { $page = $e->object; if ($page->matches("has_parent=/projects/")) { $e->return = "/projects/$page->name/"; } elseif ($page->matches("has_parent=/products/")) { $e->return = "/products/$page->name/"; } }); Nothing fancy and it works when default language is active. But when I switch to non-default langauge I get default page url. As far as I see the issue is relative to other Page::path hook in LanguageSupportPageNames.module. I was trying to prioritize hook by passing array('priority'=>2000) as last argument, but it doesn't sole the issue. Any thoughts? Link to comment Share on other sites More sharing options...
adrian Posted December 30, 2017 Share Posted December 30, 2017 Have you tried the Page::localPath hook which is actually the name of the version in the LanguageSupportPageNames.module file. Link to comment Share on other sites More sharing options...
Zeka Posted December 30, 2017 Author Share Posted December 30, 2017 Hi @adrian. Thanks for your help. Are Page:localPath, Page::localUrl hookable? I tried hook after Page::localPath, but it does nothing. Link to comment Share on other sites More sharing options...
dragan Posted December 30, 2017 Share Posted December 30, 2017 They should be, all seven listed here: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/LanguageSupport/LanguageSupportPageNames.module#L133 However, there's also this comment a few lines down, that may clash with what you're doing: // verify that page path doesn't have mixed languages where it shouldn't $redirectURL = $this->verifyPath($this->requestPath); if($redirectURL) return wire('session')->redirect($redirectURL); In your alternate languages, the pagenames for products and projects are probably different (i.e. produkte / projekte in german etc.). Link to comment Share on other sites More sharing options...
Zeka Posted December 30, 2017 Author Share Posted December 30, 2017 Hi @dragan First of all thank you for your help @adrian @dragan I was wrong about localPath and localName. They are hookable. The problem was that I never called them in my templates, so didn't get any changes. $pages->addHookAfter("Page(template=projects-category|project)::localUrl", function (HookEvent $e) {; $page = $e->object; $pages = wire('pages'); $user = wire('user'); $language = $user->language; $langSegment = $pages->get("/")->localPath($language); $pageName = $page->localName($language); if ($page->matches("has_parent=projects")) { $e->return = $langSegment . "projects/$pageName/"; } elseif ($page->matches("has_parent=products")) { $e->return = $langSegment . "products/$pageName/"; } }); Hook to Page::path also works. The issue was in my "matches" selector ))))) $pages->addHookAfter("Page(template=projects-category|project)::path", function (HookEvent $e) { $page = $e->object; $pages = wire('pages'); $user = wire('user'); $language = $user->language; $langSegment = $pages->get("/")->localPath($language); $pageName = $page->localName($language); if ($page->matches("has_parent=projects")) { $e->return = $langSegment . "projects/$pageName/"; } elseif ($page->matches("has_parent=products")) { $e->return = $langSegment . "products/$pageName/"; }; }, array('priority'=>101)); 1 Link to comment Share on other sites More sharing options...
adrian Posted December 30, 2017 Share Posted December 30, 2017 Glad you got it sorted. Just an FYI: 1 Link to comment Share on other sites More sharing options...
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