Skip to content

Commit

Permalink
feat: add otherLangUrl() for simple language switchers
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Sep 25, 2023
1 parent be5fca5 commit eb0c137
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function init()
$this->addHookBefore("Inputfield::render", $this, "addFooterlinksNote");
$this->addHookAfter("Page::changed", $this, "resetCustomLess");
$this->addHookBefore("Page::render", $this, "createCustomLess");
$this->addHookMethod("Page::otherLangUrl", $this, "otherLangUrl");

// health checks
$this->checkHealth();
Expand Down Expand Up @@ -1462,6 +1463,18 @@ public function minifyFile($file, $minFile = null): string
return $minFile->path;
}

/**
* 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
*/
public function otherLangUrl(HookEvent $event): void
{
$page = $event->object;
$lang = $this->wire->languages->findOther()->first();
$event->return = $page->localUrl($lang);
}

/**
* Apply postCSS rules to given string
*/
Expand Down

0 comments on commit eb0c137

Please sign in to comment.