function NavigationHooks::navigationMenuLinkTreeAlter

Implements hook_navigation_menu_link_tree_alter().

File

core/modules/navigation/src/Hook/NavigationHooks.php, line 295

Class

NavigationHooks
Hook implementations for navigation.

Namespace

Drupal\navigation\Hook

Code

public function navigationMenuLinkTreeAlter(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 and Content menu links.
        $plugin_id = $item->link
            ->getPluginId();
        if ($plugin_id == 'help.main' || $plugin_id == 'system.admin_content') {
            unset($tree[$key]);
        }
    }
}

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