diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php index 7137951..22f4872 100644 --- a/core/lib/Drupal/Core/Entity/EntityListBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php @@ -216,6 +216,9 @@ public function render() { '#title' => $this->getTitle(), '#rows' => array(), '#empty' => $this->t('There is no @label yet.', array('@label' => $this->entityType->getLabel())), + '#cache' => [ + 'contexts' => $this->entityType->getListCacheContexts(), + ], ); foreach ($this->load() as $entity) { if ($row = $this->buildRow($entity)) { diff --git a/core/modules/node/src/Tests/NodeListBuilderTest.php b/core/modules/node/src/Tests/NodeListBuilderTest.php new file mode 100644 index 0000000..beadf0e --- /dev/null +++ b/core/modules/node/src/Tests/NodeListBuilderTest.php @@ -0,0 +1,40 @@ +installEntitySchema('node'); + } + + + public function testCacheContexts() { + /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */ + $list_builder = $this->container->get('entity.manager')->getListBuilder('node'); + + $build = $list_builder->render(); + $this->container->get('renderer')->render($build); + + $this->assertEqual(['node_view_grants'], $build['#cache']['contexts']); + } + +} diff --git a/core/modules/system/src/Tests/Entity/EntityListBuilderTest.php b/core/modules/system/src/Tests/Entity/EntityListBuilderTest.php index 5609959..851fed8 100644 --- a/core/modules/system/src/Tests/Entity/EntityListBuilderTest.php +++ b/core/modules/system/src/Tests/Entity/EntityListBuilderTest.php @@ -56,4 +56,14 @@ public function testPager() { $this->assertRaw('Test entity 51', 'Test entity 51 is shown.'); } + public function testCacheContexts() { + /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */ + $list_builder = $this->container->get('entity.manager')->getListBuilder('entity_test'); + + $build = $list_builder->render(); + $this->container->get('renderer')->render($build); + + $this->assertEqual(['entity_test_view_grants'], $build['#cache']['contexts']); + } + } diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php index 0549257..9ea8ff5 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php @@ -33,6 +33,7 @@ * }, * base_table = "entity_test", * persistent_cache = FALSE, + * list_cache_contexts = { "entity_test_view_grants" }, * entity_keys = { * "id" = "id", * "uuid" = "uuid",