diff --git a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php index b698c74..0d53f32 100644 --- a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php +++ b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php @@ -137,11 +137,11 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) { $view->save(); } - // Continue and look at all handlers and check whether the entity type - // disappears. - // @todo How can we ensure that we don't break views. + // Unset all handlers which point to no longer existing entity types. + // @todo How can we ensure that we don't break views, see + // https://www.drupal.org/node/2401467 foreach (array_keys($view->get('display')) as $display_id) { - $display =& $view->getDisplay($display_id); + $display = &$view->getDisplay($display_id); foreach (Views::getHandlerTypes() as $handler_type) { $handler_type = $handler_type['plural']; if (!isset($display['display_options'][$handler_type])) { @@ -183,10 +183,16 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ } /** + * Updates views if a base table is renamed. + * * @param \Drupal\views\Entity\View[] $all_views + * All views. * @param string $entity_type_id + * The entity type ID. * @param string $old_base_table + * The old base table name. * @param string $new_base_table + * The new base table name. */ protected function baseTableRename($all_views, $entity_type_id, $old_base_table, $new_base_table) { foreach ($all_views as $view) { @@ -195,7 +201,7 @@ protected function baseTableRename($all_views, $entity_type_id, $old_base_table, } foreach (array_keys($view->get('display')) as $display_id) { - $display =& $view->getDisplay($display_id); + $display = &$view->getDisplay($display_id); foreach (Views::getHandlerTypes() as $handler_type) { $handler_type = $handler_type['plural']; if (!isset($display['display_options'][$handler_type])) { @@ -212,10 +218,17 @@ protected function baseTableRename($all_views, $entity_type_id, $old_base_table, } /** + * + * Updates views if a data table is renamed. + * * @param \Drupal\views\Entity\View[] $all_views + * All views. * @param string $entity_type_id + * The entity type ID. * @param string $old_data_table + * The old data table name. * @param string $new_data_table + * The new data table name. */ protected function dataTableRename($all_views, $entity_type_id, $old_data_table, $new_data_table) { foreach ($all_views as $view) { @@ -224,7 +237,7 @@ protected function dataTableRename($all_views, $entity_type_id, $old_data_table, } foreach (array_keys($view->get('display')) as $display_id) { - $display =& $view->getDisplay($display_id); + $display = &$view->getDisplay($display_id); foreach (Views::getHandlerTypes() as $handler_type) { $handler_type = $handler_type['plural']; if (!isset($display['display_options'][$handler_type])) { @@ -241,12 +254,14 @@ protected function dataTableRename($all_views, $entity_type_id, $old_data_table, } /** + * Updates views if a data table is added. + * * @param \Drupal\views\Entity\View[] $all_views + * All views. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * @param string $data_table - * @throws \Drupal\Core\Entity\EntityStorageException + * The entity type. */ - protected function dataTableAddition($all_views, EntityTypeInterface $entity_type, EntityTypeInterface $original_entity_type, $data_table) { + protected function dataTableAddition($all_views, EntityTypeInterface $entity_type) { /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage */ $entity_type_id = $entity_type->id(); $storage = $this->entityManager->getStorage($entity_type_id); @@ -257,7 +272,7 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ foreach ($all_views as $view) { foreach (array_keys($view->get('display')) as $display_id) { - $display =& $view->getDisplay($display_id); + $display = &$view->getDisplay($display_id); foreach (Views::getHandlerTypes() as $handler_type) { $handler_type = $handler_type['plural']; if (!isset($display['display_options'][$handler_type])) { @@ -276,10 +291,22 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ } } + /** + * Updates views if a data table is removed. + * + * @param \Drupal\views\Entity\View[] $all_views + * All views. + * @param string $entity_type_id + * The entity type ID. + * @param string $old_data_table + * The name of the previous existing data table. + * @param string $base_table + * The name of the base table. + */ protected function dataTableRemoval($all_views, $entity_type_id, $old_data_table, $base_table) { foreach ($all_views as $view) { foreach (array_keys($view->get('display')) as $display_id) { - $display =& $view->getDisplay($display_id); + $display = &$view->getDisplay($display_id); foreach (Views::getHandlerTypes() as $handler_type) { $handler_type = $handler_type['plural']; if (!isset($display['display_options'][$handler_type])) { @@ -298,14 +325,19 @@ protected function dataTableRemoval($all_views, $entity_type_id, $old_data_table } /** + * Updates views if a field is removed. + * * @param \Drupal\views\Entity\View[] $all_views + * All views. * @param string $entity_type_id + * The entity type ID. * @param string $field_name + * The name of the removed field. */ protected function removeFieldStorage($all_views, $entity_type_id, $field_name) { foreach ($all_views as $view) { foreach (array_keys($view->get('display')) as $display_id) { - $display =& $view->getDisplay($display_id); + $display = &$view->getDisplay($display_id); foreach (Views::getHandlerTypes() as $handler_type) { $handler_type = $handler_type['plural']; if (!isset($display['display_options'][$handler_type])) { @@ -321,4 +353,5 @@ protected function removeFieldStorage($all_views, $entity_type_id, $field_name) } } } + }