hook_menu_links_discovered_alter(&$links)
Alters all the menu links discovered by the menu link plugin manager.
array $links: The link definitions to be altered.
array An array of discovered menu links. Each link has a key that is the machine name, which must be unique. By default, use the route name as the machine name. In cases where multiple links use the same route name, such as two links to the same page in different menus, or two links using the same route name but different route parameters, the suggested machine name patten is the route name followed by a dot and a unique suffix. For example, an additional logout link might have a machine name of user.logout.navigation, and default links provided to edit the article and page content types could use machine names entity.node_type.edit_form.article and entity.node_type.edit_form.page. Since the machine name may be arbitrary, you should never write code that assumes it is identical to the route name.
The value corresponding to each machine name key is an associative array that may contain the following key-value pairs:
function hook_menu_links_discovered_alter(&$links) { // Change the weight and title of the user.logout link. $links['user.logout']['weight'] = -10; $links['user.logout']['title'] = new \Drupal\Core\StringTranslation\TranslatableMarkup('Logout'); // Conditionally add an additional link with a title that's not translated. if (\Drupal::moduleHandler()->moduleExists('search')) { $links['menu.api.search'] = array( 'title' => \Drupal::config('system.site')->get('name'), 'route_name' => 'menu.api.search', 'description' => new \Drupal\Core\StringTranslation\TranslatableMarkup('View popular search phrases for this site.'), 'parent' => 'system.admin_reports', ); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Menu!menu.api.php/function/hook_menu_links_discovered_alter/8.1.x