Skip to content

Commit

Permalink
feat: option to add urlsegmentstr to otherLangUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Oct 23, 2023
1 parent 2d84485 commit 0e4e042
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -1482,12 +1482,17 @@ public function minifyFile($file, $minFile = null): string
* Get other's language url of current page
* For super-simple language switchers, see here:
* https://processwire.com/talk/topic/12243-language-switcher-on-front-end/?do=findComment&comment=178873
*
* Provide true to add url segment string:
* $page->otherLangUrl(true);
*/
public function otherLangUrl(HookEvent $event): void
{
$page = $event->object;
$lang = $this->wire->languages->findOther()->first();
$event->return = $page->localUrl($lang);
$url = $page->localUrl($lang);
if ($event->arguments(0)) $url .= $this->wire->input->urlSegmentStr();
$event->return = $url;
}

/**
Expand Down

0 comments on commit 0e4e042

Please sign in to comment.