8.3.x contextual.module contextual_preprocess(&$variables, $hook, $info)
8.0.x contextual.module contextual_preprocess(&$variables, $hook, $info)
8.1.x contextual.module contextual_preprocess(&$variables, $hook, $info)
8.2.x contextual.module contextual_preprocess(&$variables, $hook, $info)
8.4.x contextual.module contextual_preprocess(&$variables, $hook, $info)
7.x contextual.module contextual_preprocess(&$variables, $hook)

Implements hook_preprocess().

See also

contextual_pre_render_links()

File

modules/contextual/contextual.module, line 84
Adds contextual links to perform actions related to elements on a page.

Code

function contextual_preprocess(&$variables, $hook) {
  // Nothing to do here if the user is not permitted to access contextual links.
  if (!user_access('access contextual links')) {
    return;
  }

  $hooks = theme_get_registry(FALSE);

  // Determine the primary theme function argument.
  if (!empty($hooks[$hook]['variables'])) {
    $keys = array_keys($hooks[$hook]['variables']);
    $key = $keys[0];
  }
  elseif (!empty($hooks[$hook]['render element'])) {
    $key = $hooks[$hook]['render element'];
  }
  if (!empty($key) && isset($variables[$key])) {
    $element = $variables[$key];
  }

  if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
    // Initialize the template variable as a renderable array.
    $variables['title_suffix']['contextual_links'] = array(
      '#type' => 'contextual_links',
      '#contextual_links' => $element['#contextual_links'],
      '#element' => $element,
    );
    // Mark this element as potentially having contextual links attached to it.
    $variables['classes_array'][] = 'contextual-links-region';
  }
}