hook_menu_local_tasks_alter(&$data, $route_name)
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:
- title: The localized title of the link.
- url: a Url object.
- localized_options: An array of options to pass to \Drupal\Core\Utility\LinkGeneratorInterface::generate().
- #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
- Hooks
- Define functions that alter the behavior of Drupal core.
- Menu system
- Define the navigation menus, local actions and tasks, and contextual links.
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'), ), ), ), ); }
Please login to continue.