From 600c9efb42067613d4470be8dcb145e21aba0d9d Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 31 May 2023 16:59:58 -0400 Subject: [PATCH] Fix url when using prefixDefaultLocale=true (#67) --- Plugin.php | 2 ++ classes/MLPage.php | 10 ++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Plugin.php b/Plugin.php index a692f50e..c117b1ba 100644 --- a/Plugin.php +++ b/Plugin.php @@ -380,6 +380,8 @@ function (DefinitionItem $item, array $itemInfo, Definition $definition, DOMDocu } foreach ($itemInfo['alternateLinks'] as $locale => $altUrl) { if ($locale === $defaultLocale->code) { + $loc = $urlElement->getElementsByTagName('loc')->item(0); + $loc->nodeValue = $altUrl; continue; } $newElement = $urlElement->cloneNode(true); diff --git a/classes/MLPage.php b/classes/MLPage.php index dd2a4179..53fb8628 100644 --- a/classes/MLPage.php +++ b/classes/MLPage.php @@ -27,14 +27,8 @@ public static function resolveMenuItem(object $item, string $url, Theme $theme): $alternateLinks = []; foreach ($locales as $locale => $name) { - if ($locale === $defaultLocale->code) { - $pageUrl = $result['url']; - } else { - $pageUrl = static::getLocalizedPageUrl($page, $locale); - } - if ($pageUrl) { - $alternateLinks[$locale] = Url::to($pageUrl); - } + $pageUrl = static::getLocalizedPageUrl($page, $locale) ?: $result['url']; + $alternateLinks[$locale] = Url::to($pageUrl); } if ($alternateLinks) {