function hook_menu_local_tasks

Alter tabs and actions displayed on the page before they are rendered.

This hook is invoked by menu_local_tasks(). The system-determined tabs and actions are passed in by reference. Additional tabs or actions may be added.

Each tab or action is an associative array containing:

  • #theme: The theme function to use to render.
  • #link: An associative array containing:
    • title: The localized title of the link.
    • href: The system path to link to.
    • localized_options: An array of options to pass to l().
  • #weight: The link's weight compared to other links.
  • #active: Whether the link should be marked as 'active'.

Parameters

array $data: An associative array containing:

  • actions: A list of of actions keyed by their href, each one being an associative array as described above.
  • tabs: A list of (up to 2) tab levels that contain a list of of tabs keyed by their href, each one being an associative array as described above.

array $router_item: The menu system router item of the page.

string $root_path: The path to the root item for this set of tabs.

Related topics

5 functions implement hook_menu_local_tasks()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

custom_block_menu_local_tasks in drupal/core/modules/block/custom_block/custom_block.module
Implements hook_menu_local_tasks().
forum_menu_local_tasks in drupal/core/modules/forum/forum.module
Implements hook_menu_local_tasks().
menu_test_menu_local_tasks in drupal/core/modules/system/tests/modules/menu_test/menu_test.module
Implements hook_menu_local_tasks().
node_menu_local_tasks in drupal/core/modules/node/node.module
Implements hook_menu_local_tasks().
theme_menu_local_tasks in drupal/core/includes/menu.inc
Returns HTML for primary and secondary local tasks.
1 invocation of hook_menu_local_tasks()
menu_local_tasks in drupal/core/includes/menu.inc
Collects the local tasks (tabs), action links, and the root path.

File

drupal/core/modules/system/system.api.php, line 941
Hooks provided by Drupal core and the System module.

Code

function hook_menu_local_tasks(&$data, $router_item, $root_path) {

  // Add an action linking to node/add to all pages.
  $data['actions']['node/add'] = array(
    '#theme' => 'menu_local_action',
    '#link' => array(
      'title' => t('Add new content'),
      'href' => 'node/add',
      'localized_options' => array(
        'attributes' => array(
          'title' => t('Add new content'),
        ),
      ),
    ),
  );

  // Add a tab linking to node/add to all pages.
  $data['tabs'][0]['node/add'] = array(
    '#theme' => 'menu_local_task',
    '#link' => array(
      'title' => t('Example tab'),
      'href' => 'node/add',
      'localized_options' => array(
        'attributes' => array(
          'title' => t('Add new content'),
        ),
      ),
    ),
    // Define whether this link is active. This can usually be omitted.
    '#active' => $router_item['path'] == $root_path,
  );
}