function contextual_preprocess in Drupal 7
Same name and namespace in other branches
- 8 core/modules/contextual/contextual.module \contextual_preprocess()
- 9 core/modules/contextual/contextual.module \contextual_preprocess()
- 10 core/modules/contextual/contextual.module \contextual_preprocess()
Implements hook_preprocess().
See also
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';
}
}