diff --git a/core/includes/pager.inc b/core/includes/pager.inc index eb97a5c..b358ac6 100644 --- a/core/includes/pager.inc +++ b/core/includes/pager.inc @@ -277,6 +277,10 @@ function template_preprocess_pager(&$variables) { } $variables['items'] = $items; + + // This is is based on the entire current query string. We need to ensure + // cacheability is affected accordingly. + $variables['#cache'] = ['contexts' => ['url.query_args']]; } /** @@ -313,11 +317,6 @@ function pager_query_add_page(array $query, $element, $index) { $query = array_merge($current_request_query, $query); } - // This is is based on the entire current query string. We need to ensure - // cacheability is affected accordingly. - $build = ['#cache' => ['contexts' => ['url.query_args']]]; - \Drupal::service('renderer')->render($build); - return $query; } diff --git a/core/lib/Drupal/Core/Render/Element/FormElement.php b/core/lib/Drupal/Core/Render/Element/FormElement.php index d1d2bed..fa4cec3 100644 --- a/core/lib/Drupal/Core/Render/Element/FormElement.php +++ b/core/lib/Drupal/Core/Render/Element/FormElement.php @@ -131,7 +131,7 @@ public static function processAutocomplete(&$element, FormStateInterface $form_s $element['#attributes']['data-autocomplete-path'] = $url->getGeneratedUrl(); CacheableMetadata::createFromRenderArray($element) ->merge($url) - ->merge($access) + ->merge(CacheableMetadata::createFromObject($access)) ->applyTo($element); } diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php index 3f7ffae..404f2ca 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -302,14 +302,20 @@ protected function theme($hook, $variables = array()) { $preprocessor_function($variables, $hook, $info); } } - // Allow theme preprocess functions to set $variables['#attached'] and use - // it like the #attached property on render arrays. In Drupal 8, this is - // the (only) officially supported method of attaching assets from - // preprocess functions. Assets attached here should be associated with - // the template that we're preprocessing variables for. - if (isset($variables['#attached'])) { - $preprocess_attached = ['#attached' => $variables['#attached']]; - drupal_render($preprocess_attached); + // Allow theme preprocess functions to set $variables['#attached'] and + // $variables['#cached'] and use them like the corresponding element + // properties on render arrays. In Drupal 8, this is the (only) officially + // supported method of attaching bubbleable metadata from preprocess + // functions. Assets attached here should be associated with the template + // that we are preprocessing variables for. + $preprocess_bubbleable = []; + foreach (['#attached', '#cache'] as $key) { + if (isset($variables[$key])) { + $preprocess_bubbleable[$key] = $variables[$key]; + } + } + if ($preprocess_bubbleable) { + drupal_render($preprocess_bubbleable); } } diff --git a/core/modules/system/src/Tests/Pager/PagerTest.php b/core/modules/system/src/Tests/Pager/PagerTest.php index dc643a5..7ea07fb 100644 --- a/core/modules/system/src/Tests/Pager/PagerTest.php +++ b/core/modules/system/src/Tests/Pager/PagerTest.php @@ -72,7 +72,7 @@ function testActiveClass() { /** * Test proper functioning of the query parameters and the pager cache context. */ - protected function testPagerQueryParametersAndCacheContext() { + public function testPagerQueryParametersAndCacheContext() { // First page. $this->drupalGet('pager-test/query-parameters'); $this->assertText(t('Pager calls: 0'), 'Initial call to pager shows 0 calls.'); diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 3ae454b..528b53a 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -1050,6 +1050,10 @@ function template_preprocess_views_mini_pager(&$variables) { } $variables['items']['next']['attributes'] = new Attribute(); } + + // This is is based on the entire current query string. We need to ensure + // cacheability is affected accordingly. + $variables['#cache'] = ['contexts' => ['url.query_args']]; } /**