hook_contextual_links_alter(array &$links, $group, array $route_parameters)
Alter contextual links before they are rendered.
This hook is invoked by \Drupal\Core\Menu\ContextualLinkManager::getContextualLinkPluginsByGroup(). The system-determined contextual links are passed in by reference. Additional links may be added and existing links can be altered.
Each contextual link contains the following entries:
array $links: An associative array containing contextual links for the given $group, as described above. The array keys are used to build CSS class names for contextual links and must therefore be unique for each set of contextual links.
string $group: The group of contextual links being rendered.
array $route_parameters.: The route parameters passed to each route_name of the contextual links. For example:
array('node' => $node->id())
\Drupal\Core\Menu\ContextualLinkManager
function hook_contextual_links_alter(array &$links, $group, array $route_parameters) { if ($group == 'menu') { // Dynamically use the menu name for the title of the menu_edit contextual // link. $menu = \Drupal::entityManager()->getStorage('menu')->load($route_parameters['menu']); $links['menu_edit']['title'] = t('Edit menu: @label', array('@label' => $menu->label())); } }
© 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_contextual_links_alter/8.1.x