function hook_navigation_menu_link_tree_alter

Alter the content of a given Navigation menu link tree.

Parameters

array &$tree: The Navigation link tree.

See also

\Drupal\navigation\Menu\NavigationMenuLinkTree::transform()

Related topics

2 functions implement hook_navigation_menu_link_tree_alter()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

NavigationHooks::navigationMenuLinkTreeAlter in core/modules/navigation/src/Hook/NavigationHooks.php
Implements hook_navigation_menu_link_tree_alter().
NavigationTestHooks::navigationMenuLinkTreeAlter in core/modules/navigation/tests/navigation_test/src/Hook/NavigationTestHooks.php
Implements hook_navigation_menu_link_tree_alter().
1 invocation of hook_navigation_menu_link_tree_alter()
NavigationMenuLinkTree::transform in core/modules/navigation/src/Menu/NavigationMenuLinkTree.php
Applies menu link tree manipulators to transform the given tree.

File

core/modules/navigation/navigation.api.php, line 99

Code

function hook_navigation_menu_link_tree_alter(array &$tree) : void {
  foreach ($tree as $key => $item) {
    // Skip elements where menu is not the 'admin' one.
    $menu_name = $item->link
      ->getMenuName();
    if ($menu_name != 'admin') {
      continue;
    }
    // Remove unwanted Help menu link.
    $plugin_id = $item->link
      ->getPluginId();
    if ($plugin_id == 'help.main') {
      unset($tree[$key]);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.