MenuTreeParameters::onlyEnabledLinks is ignored when building the menu tree render array

Created on 11 March 2021, almost 4 years ago
Updated 18 August 2023, over 1 year ago

Problem/Motivation

When loading the menu tree and preparing the tree to be rendered one can seemingly pass in MenuTreeParameters::onlyEnabledLinks to the load function in order to get only the enabled menu links.

One would then assume that if we don't want to limit the returned menu tree and instead we want to render all menu links regardless of whether or not they are enabled, we just have to NOT pass in the onlyEnabledLinks parameter.

Unfortunately though later on while building the render array in buildItems there is a check that removes any disabled items regardless.

// Generally we only deal with visible links, but just in case.
if (!$link->isEnabled()) {
  continue;
}

as such we can't use the core drupal build function to get the render array of the returned menu tree (unless I am missing something).

Proposed resolution

Unsure without affecting backwards compatibility.

Remaining tasks

Discuss. How can we render all the menu links of the tree regardless of whether enabled or not?

Usecase: We may not want to show certain links in the main navigation (hence disable them) but then in a menu block we want to render all links regardless. Creating a new menu just to hold duplicates of the links/tree is not desired.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Menu systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¨πŸ‡¦Canada pavlosdan

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

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.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    This was a triage target today for Bug Smash Initiative. At first glance it seemed like this is valid and a good first step would be to write a failing test. Upon further inspection this is possibly working as intended. The documentation for MenuTreeParameters reads

    Menu tree parameters are used to determine the set of definitions to be loaded from \Drupal\Core\Menu\MenuTreeStorageInterface.

    That leads me to believe that MenuTreeParameters is exclusively used for loading the tree and has no bearing on which menu links are rendered. I believe this part is working correctly, as seen towards the end of \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testLoadTree. I think this issue should be repurposed to allow \Drupal\Core\Menu\MenuLinkTree::build and ::buildItems to include disabled items, and at that point it's starting to sound like a task or feature request.

Production build 0.71.5 2024