Wrong active trail with multiple menu items with the same path

Created on 18 April 2017, about 7 years ago
Updated 15 May 2024, about 1 month ago

When the same path is added multiple times to the menu, then the menu active trail is determined by the first menu link it finds. I would expect it to pick the menu item which matches the current path.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡§πŸ‡ͺBelgium Ludo.R Brussels

    Patches in #19 and #20 do not pursue the same goal.

    I'm re-rolling patch #19 for version 2.x-dev.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    2 fail
  • πŸ‡§πŸ‡ͺBelgium Ludo.R Brussels

    Previous patch was missing a use statement, don't use #24.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    9 pass
  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    I also just had a case in a project where the current behavior was unexpected. #20 wouldn't work for me, because it wasn't a direct link, but part of the trait. In my case, the deeper menu link wasn't actually want I wanted, it was the one higher up that was in a completely different section of the site. The deeper one was actually a cross-reference from a different section of the website.

    So what would work for me is just removing the array_reverse(), which basically makes the behavior consistent with core. But that seems rather arbitrary either way. In my case, the deeper link also had extra query arguments. The logic in #19 and rerolls also seems rather arbitrary, which might or might not be what you expect.

    There's ✨ Allow other modules to alter the active link trail Needs work as well, if you want to apply extra rules on matching. For this to be committed in a BC way, the behavior would probably need to be configurable and especially if it gets as complex as latest patches, requires pretty extensive test coverage to cover all those extra checks.

Production build 0.69.0 2024