@@ -108,11 +108,6 @@ function contextual_help($route_name, RouteMatchInterface $route_match) {
108
108
* @see \Drupal\contextual\ContextualController::render()
109
109
*/
110
110
function contextual_preprocess(&$variables, $hook, $info) {
111
- $variables['#cache']['contexts'][] = 'user.permissions';
112
- if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
113
- return;
114
- }
115
-
116
111
// Determine the primary theme function argument.
117
112
if (!empty($info['variables'])) {
118
113
$keys = array_keys($info['variables']);
@@ -126,18 +121,21 @@ function contextual_preprocess(&$variables, $hook, $info) {
126
121
}
127
122
128
123
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
+ }
141
139
}
142
140
}
143
141
0 commit comments