I have been trying to create a custom menu block which shows a number of menu items with images on the current level.
I am having an issue where the active trail array doesn't return an menu item for the active node on level 4 of my menu. Here is an example of how I get the active trail:
$menu_tree = \Drupal::menuTree();
$menu_parent_tree = \Drupal::menuTree();
$menu_name = 'main';
// Build the typical default set of menu tree parameters.
$parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
foreach($parameters->activeTrail as $active_menu_link) {
if($active_menu_link !== '') {
$active_menu_id = explode(':', $active_menu_link);
$entity = \Drupal::entityManager()->loadEntityByUuid($active_menu_id[0], $active_menu_id[1]);
kint($entity->getTitle());
}
}
It seems that the issue is mostly related to the fact that the same node is linked to both a child menu item and a parent menu item. If I remove this then the function works as expected. This is the my menu structure.
The two menu items highlighted in red are both linked to the same node since I want it to act as an overview page for the category. It could be that theres something else I can do to structure the menu differently. I am open to any alternatives on how I can get around this.