Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Before adding the "expand" or "collapse" class to a menu item, we should check if the the $data['below'] is empty. I am specifically referencing menu_block.module's menu_block_tree_output() function:
<?php
...
// Set a class for the <li>-tag. Since $data['below'] may contain local
// tasks, only set 'expanded' class if the link also has children within
// the current menu.
if ($data['link']['has_children'] && $data['below']) {
$class[] = 'expanded';
}
elseif ($data['link']['has_children']) {
$class[] = 'collapsed';
}
...
?>
This might be a deeper core issues, but a small patch should fix this for Menu Block.
Comments
Comment #2
focal55 CreditAttribution: focal55 commentedComment #3
szeidler CreditAttribution: szeidler at Ramsalt Lab commentedIf you're not expanding the whole menu tree by default, checking for an empty
$data['below']
wouldn't solve the problem. That value is only non-empty when the child items should be rendered, not when the item has childrens, but they are collapsed.The issue seems to be related to the core issue #955378: Menu items - "Has children" flag is not reset on menu reordering, where the
data['has_children']
indicator is simply not up to date.