Go as deep as possible when building the active trail.

Created on 4 March 2010, about 15 years ago
Updated 21 April 2025, 5 days ago

When building active trail, Drupal assumes that the first link matching the current path is the active link.
It is not always true, especially when using the Menu Firstchild module (see http://drupal.org/node/671564 about this problem).

Consider you have this kind of menu:

item A linking to path 1
-- item B linking to path 1
---- item C linking to path 1
---- item D linking to path 2
-- item E linking to path 3

Clicking on item A, item B or item C will bring user to the same path 1.
As item A and item B are just parent containers of item C, item C should be the active link.
But Drupal shows item A as the active link, ignoring item B and item C.

To fix this bug, loop should continue until the last descendant matching current path is found:

<?php
    while ($curr) {
      // Terminate the loop when we find the current path in the active trail.
      // patch
      /*
      if ($curr['link']['href'] == $item['href']) {
        $trail[] = $curr['link'];
        $curr = FALSE;
      }
      else {
      */
        // Add the link if it's in the active trail, then move to the link below.
        if ($curr['link']['in_active_trail']) {
          $trail[] = $curr['link'];
          $tree = $curr['below'] ? $curr['below'] : array();
        }
        list($key, $curr) = each($tree);
      /*
      }
      */
      //~patch
    }
?>
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

menu system

Created by

🇫🇷France anrikun

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024