function contextual_preprocess

Same name in other branches
  1. 9 core/modules/contextual/contextual.module \contextual_preprocess()
  2. 8.9.x core/modules/contextual/contextual.module \contextual_preprocess()
  3. 10 core/modules/contextual/contextual.module \contextual_preprocess()
  4. 11.x core/modules/contextual/contextual.module \contextual_preprocess()

Implements hook_preprocess().

See also

contextual_pre_render_links()

File

modules/contextual/contextual.module, line 84

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';
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.