Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
removed "Drupal" and tags from the title
Source Link
avpaderno
  • 98.1k
  • 15
  • 165
  • 284

Drupal 8 - (Menu active trail) - Missing bottom level item when a node is linked to two menu objects

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. HereThis is an example ofthe my menu structure:.

Menu Structure for Site

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.

Let me know if theres any more details I can add.

Kind Regards,

Jamie

Drupal 8 - (Menu active trail) - Missing bottom level item when a node is linked to two menu objects

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. Here is an example of my menu structure:

Menu Structure for Site

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.

Let me know if theres any more details I can add.

Kind Regards,

Jamie

Missing bottom level item when a node is linked to two menu objects

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.

Menu Structure for Site

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.

Bumped by Community user
Source Link

Drupal 8 - (Menu active trail) - Missing bottom level item when a node is linked to two menu objects

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. Here is an example of my menu structure:

Menu Structure for Site

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.

Let me know if theres any more details I can add.

Kind Regards,

Jamie