You are here

function views_post_update_update_cacheability_metadata in Drupal 8

Update the cacheability metadata for all views.

1 string reference to 'views_post_update_update_cacheability_metadata'
UpdatePathRC1TestBaseTest::testDatabaseLoaded in core/modules/system/tests/src/Functional/Update/UpdatePathRC1TestBaseTest.php
Tests that the database was properly loaded.

File

core/modules/views/views.post_update.php, line 19
Post update functions for Views.

Code

function views_post_update_update_cacheability_metadata() {

  // Load all views.
  $views = \Drupal::entityTypeManager()
    ->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();
  }
}