Score:0

Retrieve the name of the menu that a menu link is in

cn flag

Given the code below i can get the menu link of the current page. What id like to know is how to determine what menu that link resides in.

  $current_path = \Drupal::service('path.current')->getPath();
      $params = Url::fromUri("internal:" . $current_path)->getRouteParameters();
      $entity_type = key($params);
      $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
      $menu_link = $menu_link_manager->loadLinksByRoute('entity.' . $entity_type . '.canonical', array($entity_type => $params[$entity_type]));
cn flag
Try `$menu_link[$x]->getMenuName()`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.