W3cubDocs

/Drupal 8

function hook_contextual_links_view_alter

hook_contextual_links_view_alter(&$element, $items)

Alter a contextual links element before it is rendered.

This hook is invoked by contextual_pre_render_links(). The renderable array of #type 'contextual_links', containing the entire contextual links data that is passed in by reference. Further links may be added or existing links can be altered.

Parameters

$element: A renderable array representing the contextual links.

$items: An associative array containing the original contextual link items, as generated by \Drupal\Core\Menu\ContextualLinkManagerInterface::getContextualLinksArrayByGroup(), which were used to build $element['#links'].

See also

hook_contextual_links_alter()

hook_contextual_links_plugins_alter()

contextual_pre_render_links()

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/modules/contextual/contextual.api.php, line 33
Hooks provided by Contextual module.

Code

function hook_contextual_links_view_alter(&$element, $items) {
  // Add another class to all contextual link lists to facilitate custom
  // styling.
  $element['#attributes']['class'][] = 'custom-class';
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!contextual!contextual.api.php/function/hook_contextual_links_view_alter/8.1.x