Skip to content
Merged
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
11 changes: 7 additions & 4 deletions dxpr_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ function dxpr_theme_preprocess_menu(&$variables) {
}

$current_path = \Drupal::service('path.current')->getPath();
dxpr_theme_menu_set_active_trail($variables['items'], $current_path);
$is_front = \Drupal::service('path.matcher')->isFrontPage();
dxpr_theme_menu_set_active_trail($variables['items'], $current_path, $is_front);

// Ensure menu is cached per URL to prevent wrong active states.
$variables['#cache']['contexts'][] = 'url.path';
Expand All @@ -304,11 +305,13 @@ function dxpr_theme_preprocess_menu(&$variables) {
* Menu items array (passed by reference).
* @param string $current_path
* Current page path (e.g., "/test-view").
* @param bool $is_front
* Whether the current page is the front page.
*
* @return bool
* TRUE if any item in this level or below is active.
*/
function dxpr_theme_menu_set_active_trail(array &$items, $current_path) {
function dxpr_theme_menu_set_active_trail(array &$items, $current_path, $is_front) {
$has_active = FALSE;

foreach ($items as &$item) {
Expand All @@ -323,7 +326,7 @@ function dxpr_theme_menu_set_active_trail(array &$items, $current_path) {
$item_path = $item['url'] instanceof
Url ? $item['url']->toString()
: (string) $item['url'];
if ($item_path === $current_path) {
if ($item_path === $current_path || ($is_front && $item_path === '/')) {
$item['in_active_trail'] = TRUE;
$item['is_active'] = TRUE;
$is_active = TRUE;
Expand All @@ -334,7 +337,7 @@ function dxpr_theme_menu_set_active_trail(array &$items, $current_path) {
}

if (!empty($item['below'])) {
$child_active = dxpr_theme_menu_set_active_trail($item['below'], $current_path);
$child_active = dxpr_theme_menu_set_active_trail($item['below'], $current_path, $is_front);
if ($child_active && empty($item['in_active_trail'])) {
$item['in_active_trail'] = TRUE;
}
Expand Down
Loading