diff --git a/oe_whitelabel.theme b/oe_whitelabel.theme index c3805bbfecb449cf6290bb44a2433c0e14542c66..87447e810ff5da233bb7b1b63d11f9af26497714 100644 --- a/oe_whitelabel.theme +++ b/oe_whitelabel.theme @@ -11,40 +11,45 @@ declare(strict_types = 1); * Implements hook__preprocess_links__language_block(). */ function oe_whitelabel_preprocess_links__language_block(&$variables) { - /** @var \Drupal\Core\Language\LanguageInterface[] $original_languages */ - $original_languages = \Drupal::service('language_manager')->getNativeLanguages(); - $currentLanguage = \Drupal::languageManager()->getCurrentLanguage()->getName(); - $variables['language']['link'] = [ - 'label' => $currentLanguage, - 'href' => $currentLanguage, - 'target' => 'languageModal', - ]; - + $currentLanguage = \Drupal::languageManager()->getCurrentLanguage(); + $current_language_id = $currentLanguage->getId(); + $language_config_storage = \Drupal::entityTypeManager()->getStorage('configurable_language'); $eu_links = []; $non_eu_links = []; - foreach ($original_languages as $language) { - $url = $variables['links'][$language->getId()]['link']['#url']; - $host = \Drupal::request()->getHost(); - - if ($language->getId() !== $currentLanguage) { - if ($language->getThirdPartySetting('oe_multilingual', 'category') === 'eu') { - $eu_links[$language->getId()] = [ - 'name' => $language->getName(), - 'href' => base_path() . $language->getId() . '/' . $url->getInternalPath(), - 'id' => 'link_' . $language->getId(), - ]; - } - else { - $non_eu_links[$language->getId()] = [ - 'name' => $language->getName(), - 'href' => base_path() . $language->getId() . '/' . $url->getInternalPath(), - 'id' => 'link_' . $language->getId(), - ]; - } + + foreach ($variables['links'] as $language_code => $link) { + /** @var \Drupal\Core\Url $url */ + $url = $link['link']['#url']; + $href = $url + ->setOptions($link['link']['#options']) + ->setAbsolute(TRUE) + ->toString(); + $label = $link['link']['#title']; + + $link = [ + 'href' => $href, + 'name' => $label, + 'id' => 'link_' . $language_code, + 'hreflang' => $language_code, + ]; + + if (!empty($current_language_id) && $language_code === $current_language_id) { + $variables['language']['link'] = $link; + $variables['language']['link']['target'] = 'languageModal'; + $link['active'] = TRUE; + } + + $language_config = $language_config_storage->load($language_code); + $category = $language_config->getThirdPartySetting('oe_multilingual', 'category'); + + if ($category === 'eu') { + $eu_links[$language_code] = $link; + } + else { + $non_eu_links[$language_code] = $link; } } - unset($variables['links']); $variables['language']['modal'] = [ 'id' => 'languageModal', 'size' => 'fullscreen', @@ -58,6 +63,4 @@ function oe_whitelabel_preprocess_links__language_block(&$variables) { 'label' => t('Close'), ], ]; - unset($variables['links']); - } diff --git a/templates/overrides/navigation/links--language-block.html.twig b/templates/overrides/navigation/links--language-block.html.twig index 15bb2fb795859124135779382e5db1dd4912eb11..cf2369ba9632cfec5f429d56cbc3ed7f4204b404 100644 --- a/templates/overrides/navigation/links--language-block.html.twig +++ b/templates/overrides/navigation/links--language-block.html.twig @@ -11,7 +11,7 @@ {% set _language = { link: { - label: language.link.label|default(''), + label: language.link.name|default(''), href: language.link.href|default('#'), target: language.link.target|default(language.modal.id|default('')), }, @@ -27,7 +27,7 @@ <li class="nav-item"> {{ pattern('link', { label: _language.link.label, - path: _language.link.label, + path: _language.link.href, icon: { name: 'chat-left-dots-fill', size: 's'