.../Update/CacheabilityMetadataUpdateTest.php | 47 ++++++++++++++++++++++ core/modules/views/views.post_update.php | 36 +++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/core/modules/views/src/Tests/Update/CacheabilityMetadataUpdateTest.php b/core/modules/views/src/Tests/Update/CacheabilityMetadataUpdateTest.php new file mode 100644 index 0000000..4f463f3 --- /dev/null +++ b/core/modules/views/src/Tests/Update/CacheabilityMetadataUpdateTest.php @@ -0,0 +1,47 @@ +databaseDumpFiles = [__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz']; + } + + /** + * Tests that views cacheability metadata updated properly. + */ + public function testUpdateHookN() { + $this->runUpdates(); + foreach (Views::getAllViews() as $view) { + $displays = $view->get('display'); + foreach (array_keys($displays) as $display_id) { + $display = $view->getDisplay($display_id); + $this->assertFalse(isset($display['cache_metadata']['cacheable'])); + $this->assertTrue(isset($display['cache_metadata']['contexts'])); + $this->assertTrue(isset($display['cache_metadata']['max-age'])); + $this->assertTrue(isset($display['cache_metadata']['tags'])); + } + } + } + +} diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php new file mode 100644 index 0000000..5d248a5 --- /dev/null +++ b/core/modules/views/views.post_update.php @@ -0,0 +1,36 @@ +getStorage('view')->loadMultiple(); + + /* @var \Drupal\views\Entity\View[] $views */ + foreach ($views as $view) { + $displays = $view->get('display'); + foreach (array_keys($displays) as $display_id) { + $display =& $view->getDisplay($display_id); + // Unset the cache_metadata key, so all cacheability metadata for the + // display is recalculated. + unset($display['cache_metadata']); + } + $view->save(); + } + +} + +/** + * @} End of "addtogroup updates-8.0.0-beta". + */