diff --git a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php index 825a6407d1d411f853812fd94d5d9dc36bc2d385..f8f5ea845be160ee3033a9620a51f8bcbd0c7b64 100644 --- a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php +++ b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php @@ -83,6 +83,13 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS */ protected $logger; + /** + * Array of views that need to be saved, indexed by view name. + * + * @var \Drupal\views\ViewEntityInterface[] + */ + protected $viewsToSave = []; + /** * Constructs a ViewsEntitySchemaSubscriber. * @@ -208,17 +215,12 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI } } - // Filter the list of views that needs to be updated. - $views_to_update = array_filter($all_views, function (ViewEntityInterface $view) { - return $view->get('_updated') === TRUE; - }); - foreach ($views_to_update as $view) { + foreach ($this->viewsToSave as $view) { try { // All changes done to the views here can be trusted and this might be // called during updates, when it is not safe to rely on configuration // containing valid schema. Trust the data and disable schema validation // and casting. - $view->set('_updated', NULL); $view->trustData()->save(); } catch (\Exception $e) { @@ -231,6 +233,7 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI ]); } } + $this->viewsToSave = []; } /** @@ -300,14 +303,14 @@ protected function baseTableRename($all_views, $entity_type_id, $old_base_table, foreach ($all_views as $view) { if ($view->get('base_table') == $old_base_table) { $view->set('base_table', $new_base_table); - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } } $this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_base_table, $new_base_table) { if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id && $handler_config['table'] == $old_base_table) { $handler_config['table'] = $new_base_table; - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } }); } @@ -328,14 +331,14 @@ protected function dataTableRename($all_views, $entity_type_id, $old_data_table, foreach ($all_views as $view) { if ($view->get('base_table') == $old_data_table) { $view->set('base_table', $new_data_table); - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } } $this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_data_table, $new_data_table) { if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id && $handler_config['table'] == $old_data_table) { $handler_config['table'] = $new_data_table; - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } }); } @@ -368,7 +371,7 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ // Move all fields which just exists on the data table. if ($handler_config['table'] == $base_table && in_array($handler_config['entity_field'], $data_table_fields) && !in_array($handler_config['entity_field'], $base_table_fields)) { $handler_config['table'] = $data_table; - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } } }); @@ -392,7 +395,7 @@ protected function dataTableRemoval($all_views, $entity_type_id, $old_data_table if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id) { if ($handler_config['table'] == $old_data_table) { $handler_config['table'] = $base_table; - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } } }); @@ -414,7 +417,7 @@ protected function revisionRemoval($all_views, EntityTypeInterface $original) { if (in_array($view->get('base_table'), [$revision_base_table, $revision_data_table])) { // Let's disable the views as we no longer support revisions. $view->setStatus(FALSE); - $view->set('_updated', TRUE); + $this->viewsToSave[$view->id()] = $view; } // For any kind of field, let's rely on the broken handler functionality.