8.5.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
8.0.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
8.1.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
8.2.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
8.3.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
8.4.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
8.6.x contextual.api.php hook_contextual_links_view_alter(&$element, $items)
7.x contextual.api.php 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 menu_contextual_links(), which were used to build $element['#links'].

See also

hook_menu_contextual_links_alter()

contextual_pre_render_links()

contextual_element_info()

Related topics

1 invocation of hook_contextual_links_view_alter()
contextual_pre_render_links in modules/contextual/contextual.module
Build a renderable array for contextual links.

File

modules/contextual/contextual.api.php, line 32
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';
}

Comments

pfrenssen’s picture

Replace the 'configure block' contextual link of a custom block with a node edit link.

/**
 * Implements hook_contextual_links_view_alter().
 */
function MODULE_NAME_contextual_links_view_alter(&$element, $items) {
  if(isset($element['#element']['#block']->module) && $element['#element']['#block']->module == 'block' && $element['#element']['#block']->delta == 1) {
    $links = &$element['#links'];
    unset($links['block-configure']);
    $links['node-edit'] = array(
      'title' => t('Edit node'),
      'href' => 'node/1/edit',
    );
  }
}