Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions web/themes/interledger/interledger.theme
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use \Drupal\Core\Url;

/**
* Implements hook_preprocess()
*
Expand Down Expand Up @@ -32,3 +34,35 @@ function interledger_preprocess_html(&$variables) {
$variables['attributes']['class'][] = 'page-' . $statusCode;
}
}

/**
* Prepares variables for the menu--main template.
*
* Default template: menu--main.html.twig.
*
* See the menu--main.html.twig template for the list of variables.
*/
function interledger_preprocess_menu__main(&$variables) {
$default_lang_code = strtolower(\Drupal::languageManager()->getDefaultLanguage()->getId());
$lang_code = strtolower(\Drupal::languageManager()->getCurrentLanguage()->getId());
$needs_translation = $lang_code !== $default_lang_code;

if ($variables['menu_name'] === 'main' && $needs_translation) {
$path_to_translate = '/developers';
$translated_path = 'developers/' . $lang_code;
foreach ($variables['items'] as $key => $item) {
if (!empty($item['below']) && is_array($item["below"])) {
foreach ($item['below'] as $skey => $submenu) {
if (isset($submenu['url']) && is_object($submenu['url'])) {
$url_string = strtolower($submenu['url']->toString());
if (str_starts_with($url_string, $path_to_translate)) {
$translationStr = substr_replace($url_string, $translated_path, 0, strlen($path_to_translate));
$translationUrl = Url::fromUri('base:' . $translationStr);
$variables['items'][$key]['below'][$skey]['url'] = $translationUrl;
}
}
}
}
}
}
}