Issue #2580263 by Berdir, nils.destoop, catch, Cottser, larowlan: Find a way to not run contextual_preprocess() on every template
parent
a1c4ca7b0c
commit
cffeb24f20
|
@ -108,11 +108,6 @@ function contextual_help($route_name, RouteMatchInterface $route_match) {
|
||||||
* @see \Drupal\contextual\ContextualController::render()
|
* @see \Drupal\contextual\ContextualController::render()
|
||||||
*/
|
*/
|
||||||
function contextual_preprocess(&$variables, $hook, $info) {
|
function contextual_preprocess(&$variables, $hook, $info) {
|
||||||
$variables['#cache']['contexts'][] = 'user.permissions';
|
|
||||||
if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the primary theme function argument.
|
// Determine the primary theme function argument.
|
||||||
if (!empty($info['variables'])) {
|
if (!empty($info['variables'])) {
|
||||||
$keys = array_keys($info['variables']);
|
$keys = array_keys($info['variables']);
|
||||||
|
@ -126,6 +121,8 @@ function contextual_preprocess(&$variables, $hook, $info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
|
if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
|
||||||
|
$variables['#cache']['contexts'][] = 'user.permissions';
|
||||||
|
if (\Drupal::currentUser()->hasPermission('access contextual links')) {
|
||||||
// Mark this element as potentially having contextual links attached to it.
|
// Mark this element as potentially having contextual links attached to it.
|
||||||
$variables['attributes']['class'][] = 'contextual-region';
|
$variables['attributes']['class'][] = 'contextual-region';
|
||||||
|
|
||||||
|
@ -139,6 +136,7 @@ function contextual_preprocess(&$variables, $hook, $info) {
|
||||||
'#id' => _contextual_links_to_id($element['#contextual_links']),
|
'#id' => _contextual_links_to_id($element['#contextual_links']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue