Problem/Motivation

The core system for retrieving the active menu trail does not check if the matching menu link is enabled or disabled. This can lead to several problems when a menu link is disabled, such as an "active" class inappropriately set on a parent menu link, or a wrong breadcrumb if Menu Breadcrumb is used.

A similar problem can happen if the matching menu link is active but one of its parent links is disabled. But:
* this would be a very strange use case,
* I don't know what we should expect from such a configuration,
* in that case, the problem could be easily avoided by also disabling the matching menu link,
* handle this would require to load all the parents to check if they are enabled, which might harm performance.

So I guess we only need to handle the case where the matching menu link is disabled. Here's a patch.

Steps to reproduce

Create menu items with this structure in the main menu:

  • Node 1 (enabled)
    • Node 2 (disabled)

Browse to Node 2 and inspect the menu markup: the Node 1 menu item has the primary-nav__menu-link--active-trail class.

Proposed resolution

Disabled menu items should not be used to generate the active trail.

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

We should add a heads-up to the release notes, since some sites might rely on the previous buggy behaviour (see #36):

<p>When retrieving the active menu trail, <a href="/node/3544512">disabled menu links will no longer be taken into account</a>.</p>

Issue fork drupal-2973515

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

GaëlG created an issue. See original summary.

borisson_’s picture

Issue tags: +Needs tests

We should add tests for this usecase so that we confirm this patch actually resolves the issue.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

Status: Needs review » Needs work

Setting to needs work because tests are needed.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

pameeela’s picture

mohit_aghera made their first commit to this issue’s fork.

mohit_aghera’s picture

Status: Needs work » Needs review

Added PR with initial test cases https://git.drupalcode.org/project/drupal/-/merge_requests/369
Test cases need some review.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.5.x-dev » 10.0.x-dev
Issue summary: View changes
Issue tags: +Bug Smash Initiative

The new test is failing setting to NW. I have not reviewed the patch or the test.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Seems there was a test failure in the MR.

Hiding patch as fix is in MR.

mohit_aghera’s picture

I tried to reproduce the issue manually using following approach:
My menu tree looks like given below
- Home
- Parent (path: node/)
--Node 1 (active) (path: node/1)
--Node 2 (disabled) (path: node/2)

Now when I visit node/2 in the browser directly, i can see proper menu tree in the UI
Besides, I don't see any `is-active` class applied to Parent or Home menu links.
Can we get additional steps to reproduce the issue.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

prudloff’s picture

Issue summary: View changes

prudloff changed the visibility of the branch 9.2.x to hidden.

prudloff changed the visibility of the branch 11.x to hidden.

prudloff changed the visibility of the branch 2973515-menuactivetrail-should-ignore to hidden.

prudloff’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I added steps to reproduce and created a new MR that targets 11.x.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

https://git.drupalcode.org/issue/drupal-2973515/-/jobs/4680214 shows the test coverage and the actual fix seems pretty straight forward to me.

catch’s picture

I left a minor comment on the MR, which is a bit of a nitpick and I'm 50/50 whether it's in scope or not. Back to needs review, but would be fine with either fixing it here or opening a follow-up.

catch’s picture

Status: Reviewed & tested by the community » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Seems fair

shalini_jha made their first commit to this issue’s fork.

shalini_jha’s picture

Status: Needs work » Needs review

I have gone through the feedback on the MR and addressed the requested changes.I also re-ran the tests locally, and they are passing.
Moving this back to Needs Review for further feedback.kindly review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback addressed

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Reviewed & tested by the community

Merged the latest 11.x.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

I've just done some profiling of a site that was relying on this behaviour - a very large menu with about 180 enabled links and 1500+ disabled links, the disabled links are being used so that menu_breadcrumb will match the disabled links to the enabled parent items.

That set-up is causing other problems but would definitely break as a result of the fix here, so on the basis that potentially more than one site might be doing some version of this, I think we need a release note and a change record.

prudloff’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
smustgrave’s picture

Regarding #36 do we think this would warrant a deprecated sub module to maintain existing behavior that would be removed in D13?

smustgrave’s picture

Know it's hard to know but

If you rely on the previous behavior you might need to adapt your code.

feel as a CR it should have an example of what "adapt your code" is.

smustgrave’s picture

Status: Needs review » Needs work

re-reading #36 also mentions a release note

If no one else has a concern #39 it can be ignored.

feyp’s picture

Issue summary: View changes
Status: Needs work » Needs review

Just ran into this once more and the MR fixes it nicely, thanks for working on this.

Actually, I agree with #39. We don't provide an API to disable the new behaviour, so I think just "adapting the code" isn't a solution. I have removed this paragraph from the CR. The whole CR is more like a heads-up for people who might possibly rely on this behavior so that they can look into how to best deal with removal of this bug before updating. I don't think we actually need to provide a "solution" to restore the buggy behavior in the CR. "There is no replacement"-CRs are also not that uncommon, so it should be fine that way for this obvious bug.

Likewise, I don't think we should add an API to restore the old behavior and then provide a BC layer (most likely including UI so that you could enable it somehow) just to remove all of it again in Drupal 13. I don't think the case in #36 is common enough to warrant this and @catch didn't ask for it.

I added a release note to the IS and also added a sentence on why we think a release note might be a good idea.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

CR definitely reads more like a "heads up" change now. Believe all feedback has been addressed here

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

john.oltman’s picture

We needed this (patch based on the MR) after upgrading from Drupal 11.2.9 to 11.3.2, otherwise would get an exception from the menu_breadcrumb module for any page with a disabled menu item.

I'll post over there as well.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest 11.x.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Restoring status from the bot.

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

One minor comment on the MR.

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Applied the suggestion. Verified the docs too allow for null return \Drupal\Core\Menu\MenuLinkInterface|null just in case

smustgrave’s picture

Also rebased this as think it would be a good thing for D12 to have, maybe it should be tagged as a priority or highlight item?

  • godotislate committed 9f591ba9 on main
    fix: #2973515 MenuActiveTrail should ignore disabled menu links
    
    By:...

  • godotislate committed 300d7195 on 11.x
    fix: #2973515 MenuActiveTrail should ignore disabled menu links
    
    By:...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushedt to main and 11.x. Published the CR for 11.4.0. Thanks, everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joelpittet’s picture

I think I’ve been using this as a feature not a bug. I could trick the breadcrumbs into giving a path back from a page I didn’t want visible in the menu. I guess I should give more attention to menu_item_visibility module now. Or some menu_position rule

rmantics’s picture

Same here. Our uni had relied on this as a feature for some custom menu building paragraph types we had in place. (In addition to the breadcrumbs) Trying to figure out how best to handle after migrating our site to Drupal 11.

Did you find a good approach @joelpittet?

alexander tallqvist’s picture

StatusFileSize
new987 bytes

Quite a few of our sites also rely on this behaviour. For now, I’ve created a patch that reverts the change while I look for a better long-term solution.

briangon’s picture

-1 ... Was relying on this, and the D11 upgrade turfed it.
I can lean on menu_position -- but for one-off links this was more elegant.
Will appreciate the patches and/or a custom mod to keep it reversed.