Commit 4112ca13 authored by alexpott's avatar alexpott

Issue #2462851 by rpayanm, Wim Leers: Improve Views entity row renderer plugins' cache contexts

parent ccfaa23e
......@@ -75,7 +75,7 @@ public function isCacheable() {
* {@inheritdoc}
*/
public function getCacheContexts() {
return ['languages'];
return [];
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\views\Entity\Render;
use Drupal\Core\Language\LanguageInterface;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ResultRow;
......@@ -75,4 +76,10 @@ public function getLangcode(ResultRow $row) {
return isset($row->{$this->langcodeAlias}) ? $row->{$this->langcodeAlias} : $this->languageManager->getDefaultLanguage()->getId();
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return ['languages:' . LanguageInterface::TYPE_CONTENT];
}
}
......@@ -88,7 +88,7 @@ public function testGlossaryView() {
// Verify cache tags.
$this->enablePageCaching();
$this->assertPageCacheContextsAndTags(Url::fromRoute('view.glossary.page_1'), ['languages', 'theme', 'url', 'user.node_grants:view', 'user.permissions'], [
$this->assertPageCacheContextsAndTags(Url::fromRoute('view.glossary.page_1'), ['languages:' . LanguageInterface::TYPE_CONTENT, 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url', 'user.node_grants:view', 'user.permissions'], [
'config:views.view.glossary',
'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(),
'node_list',
......
......@@ -222,7 +222,7 @@ public function testViewAddCacheMetadata() {
$view = View::load('test_display');
$view->save();
$this->assertEqual(['languages', 'languages:' . LanguageInterface::TYPE_INTERFACE, 'user.node_grants:view'], $view->getDisplay('default')['cache_metadata']['contexts']);
$this->assertEqual(['languages:' . LanguageInterface::TYPE_CONTENT, 'languages:' . LanguageInterface::TYPE_INTERFACE, 'user.node_grants:view'], $view->getDisplay('default')['cache_metadata']['contexts']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment