function hook_menu_contextual_links_alter
Alter contextual links before they are rendered.
This hook is invoked by menu_contextual_links(). The system-determined contextual links are passed in by reference. Additional links may be added or existing links can be altered.
Each contextual link must at least contain:
- title: The localized title of the link.
- href: The system path to link to.
- localized_options: An array of options to pass to url().
Parameters
$links: An associative array containing contextual links for the given $root_path, 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.
$router_item: The menu router item belonging to the $root_path being requested.
$root_path: The (parent) path that has been requested to build contextual links for. This is a normalized path, which means that an originally passed path of 'node/123' became 'node/%'.
See also
hook_contextual_links_view_alter()
Related topics
1 invocation of hook_menu_contextual_links_alter()
- menu_contextual_links in includes/
menu.inc - Retrieves contextual links for a path based on registered local tasks.
File
-
modules/
system/ system.api.php, line 1561
Code
function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) {
// Add a link to all contextual links for nodes.
if ($root_path == 'node/%') {
$links['foo'] = array(
'title' => t('Do fu'),
'href' => 'foo/do',
'localized_options' => array(
'query' => array(
'foo' => 'bar',
),
),
);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.