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();
$parameters->setRoot($element->link->getPluginId())->excludeRoot();
$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.
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.)