You are here

function hook_menu_contextual_links_alter in Drupal 7

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()

menu_contextual_links()

hook_menu()

contextual_preprocess()

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
Hooks provided by Drupal core and the System module.

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',
        ),
      ),
    );
  }
}