Skip to content

Commit 1693614

Browse files
committed
Issue #2580263 by Berdir, nils.destoop, catch, Cottser, larowlan: Find a way to not run contextual_preprocess() on every template
1 parent cdaa87e commit 1693614

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

modules/contextual/contextual.module

+15-17
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ function contextual_help($route_name, RouteMatchInterface $route_match) {
108108
* @see \Drupal\contextual\ContextualController::render()
109109
*/
110110
function contextual_preprocess(&$variables, $hook, $info) {
111-
$variables['#cache']['contexts'][] = 'user.permissions';
112-
if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
113-
return;
114-
}
115-
116111
// Determine the primary theme function argument.
117112
if (!empty($info['variables'])) {
118113
$keys = array_keys($info['variables']);
@@ -126,18 +121,21 @@ function contextual_preprocess(&$variables, $hook, $info) {
126121
}
127122

128123
if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
129-
// Mark this element as potentially having contextual links attached to it.
130-
$variables['attributes']['class'][] = 'contextual-region';
131-
132-
// Renders a contextual links placeholder unconditionally, thus not breaking
133-
// the render cache. Although the empty placeholder is rendered for all
134-
// users, contextual_page_attachments() only adds the asset library for
135-
// users with the 'access contextual links' permission, thus preventing
136-
// unnecessary HTTP requests for users without that permission.
137-
$variables['title_suffix']['contextual_links'] = [
138-
'#type' => 'contextual_links_placeholder',
139-
'#id' => _contextual_links_to_id($element['#contextual_links']),
140-
];
124+
$variables['#cache']['contexts'][] = 'user.permissions';
125+
if (\Drupal::currentUser()->hasPermission('access contextual links')) {
126+
// Mark this element as potentially having contextual links attached to it.
127+
$variables['attributes']['class'][] = 'contextual-region';
128+
129+
// Renders a contextual links placeholder unconditionally, thus not breaking
130+
// the render cache. Although the empty placeholder is rendered for all
131+
// users, contextual_page_attachments() only adds the asset library for
132+
// users with the 'access contextual links' permission, thus preventing
133+
// unnecessary HTTP requests for users without that permission.
134+
$variables['title_suffix']['contextual_links'] = [
135+
'#type' => 'contextual_links_placeholder',
136+
'#id' => _contextual_links_to_id($element['#contextual_links']),
137+
];
138+
}
141139
}
142140
}
143141

0 commit comments

Comments
 (0)