You are here

function hook_menu_local_tasks_alter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Menu/menu.api.php \hook_menu_local_tasks_alter()

Alter local tasks 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 may be added.

The local tasks are under the 'tabs' element and keyed by plugin ID.

Each local task is an associative array containing:

  • #theme: The theme function to use to render.
  • #link: An associative array containing:
  • #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 list of (up to 2) tab levels that contain a list of tabs keyed by their href, each one being an associative array as described above.

string $route_name: The route name of the page.

Related topics

2 functions implement hook_menu_local_tasks_alter()

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

contact_menu_local_tasks_alter in core/modules/contact/contact.module
Implements hook_menu_local_tasks_alter().
menu_test_menu_local_tasks_alter in core/modules/system/tests/modules/menu_test/menu_test.module
Implements hook_menu_local_tasks_alter().
1 invocation of hook_menu_local_tasks_alter()
LocalTaskManager::getLocalTasks in core/lib/Drupal/Core/Menu/LocalTaskManager.php
Collects the local tasks (tabs) for the current route.

File

core/lib/Drupal/Core/Menu/menu.api.php, line 307
Hooks and documentation related to the menu system and links.

Code

function hook_menu_local_tasks_alter(&$data, $route_name) {

  // Add a tab linking to node/add to all pages.
  $data['tabs'][0]['node.add_page'] = array(
    '#theme' => 'menu_local_task',
    '#link' => array(
      'title' => t('Example tab'),
      'url' => Url::fromRoute('node.add_page'),
      'localized_options' => array(
        'attributes' => array(
          'title' => t('Add content'),
        ),
      ),
    ),
  );
}