When loading a menu tree without any custom parameters:

$tree = \Drupal::menuTree()->load('my-menu-name', new MenuTreeParameters());

The returned tree \Drupal\Core\Menu\MenuLinkTreeElement[] includes disabled items, which is what I want. I did not set onlyEnabledLinks() or addCondition('enabled', 1) to the MenuTreeParameters.

For some reason, though, every subtree returned beyond the root level excludes disabled items. Even if I re-query each subtree, it still happens:

foreach ($tree as $element) {
    // Do stuff
    $parameters = new MenuTreeParameters();
    $subtree = \Drupal::menuTree()->load('my-menu-name', $parameters);

The only way I have found to include disabled items so far has been to re-query each subtree twice with $parameters->addCondition('enabled', 1); and $parameters->addCondition('enabled', 0);, which is ridiculous.

I can't find anything in the documentation to suggest this is the correct behavior of Drupal, but I'm hoping someone can spot something I'm missing before I submit a bug report. This is in Drupal 9.1.

  • This is not the behavior I see - I see the disabled items in my subtrees.
    – sonfd
    Feb 20, 2021 at 13:02
  • I uninstalled all modules except core and used the default theme, and this still happens. Are there any other sources of potential menu manipulation I am missing?
    – Anton
    Feb 20, 2021 at 19:44
  • @sonfd Can you confirm you're using Drupal 9.1?
    – Anton
    Feb 22, 2021 at 10:32
  • I may have originally been on 8.9 (not sure), but I did just test on 9.1.4 with minimal install and I'm seeing all items in the tree. I have a hook_preprocess_page() with $tree = \Drupal::menuTree()->load('admin', new MenuTreeParameters()); with a breakpoint on the next line. I've disabled Structure and Structure > Display Modes menu items. When I load a page and hit my breakpoint, I see the whole tree in my var, disabled items and their subtrees included. (Sorry I'm so slow getting back to you.)
    – sonfd
    Mar 7, 2021 at 14:19
  • Most likely related to drupal.org/project/drupal/issues/3202930
    – MrUpsidown
    Jul 26, 2021 at 10:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.