diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index dac7b88..7524059 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -336,7 +336,8 @@ protected function prepareResults(StatementInterface $found) { 'score' => $item->calculated_score, 'snippet' => search_excerpt($keys, $node->rendered, $item->langcode), 'langcode' => $node->language()->getId(), - 'cache_tags' => $build['#cache']['tags'] + 'cache_tags' => $build['#cache']['tags'], + 'cache_contexts' => array('user.node_grants:view'), ); } return $results; diff --git a/core/modules/search/src/Controller/SearchController.php b/core/modules/search/src/Controller/SearchController.php index a710fa2..3af9863 100644 --- a/core/modules/search/src/Controller/SearchController.php +++ b/core/modules/search/src/Controller/SearchController.php @@ -106,6 +106,7 @@ public function view(Request $request, SearchPageInterface $entity) { $results += array( 'cache_tags' => array(), + 'cache_contexts' => array(), 'items' => array(), ); @@ -129,7 +130,8 @@ public function view(Request $request, SearchPageInterface $entity) { ), ), '#cache' => array( - 'tags' => array_merge($entity->getCacheTags(), $results['cache_tags']), + 'tags' => Cache::mergeTags($entity->getCacheTags(), $results['cache_tags']), + 'contexts' => Cache::mergeContexts($entity->getCacheContexts(), $results['cache_contexts']), ), ); diff --git a/core/modules/search/src/Plugin/SearchInterface.php b/core/modules/search/src/Plugin/SearchInterface.php index ebf719e..6af470d 100644 --- a/core/modules/search/src/Plugin/SearchInterface.php +++ b/core/modules/search/src/Plugin/SearchInterface.php @@ -88,11 +88,13 @@ public function execute(); * Executes the search and builds render arrays for the result items. * * @return array - * An array that has 'items' and 'cache_tags' arrays. The 'items' array is - * an array of render arrays of search result items (generally each item - * has '#theme' set to 'search_result'), or an empty array if there are no - * results. The 'cache_tags' array holds all the cache tags associated with - * the items in the 'items' array. + * An array that has 'items', 'cache_tags' and 'cache_contexts' arrays. + * The 'items' array is an array of render arrays of search result items + * (generally each items has '#theme' set to 'search_result'), + * or an empty array if there are no results. + * The 'cache_tags' array holds all the cache tags associated with the items + * in the 'items' array. The 'cache_contexts' array holds the contexts for + * all the the search page. */ public function buildResults(); diff --git a/core/modules/search/src/Plugin/SearchPluginBase.php b/core/modules/search/src/Plugin/SearchPluginBase.php index e0bd857..61b664f 100644 --- a/core/modules/search/src/Plugin/SearchPluginBase.php +++ b/core/modules/search/src/Plugin/SearchPluginBase.php @@ -7,6 +7,7 @@ namespace Drupal\search\Plugin; +use Drupal\Core\Cache\Cache; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -101,6 +102,7 @@ public function buildResults() { $built = array( 'cache_tags' => array(), 'items' => array(), + 'cache_contexts' => array(), ); foreach ($results as $result) { $built['items'][] = array( @@ -108,7 +110,8 @@ public function buildResults() { '#result' => $result, '#plugin_id' => $this->getPluginId(), ); - $built['cache_tags'] = array_merge($built['cache_tags'], $result['cache_tags']); + $built['cache_tags'] = Cache::mergeTags($built['cache_tags'], $result['cache_tags']); + $built['cache_contexts'] = Cache::mergeContexts($built['cache_contexts'], $result['cache_contexts']); } return $built;