You are here

public function ViewsEntitySchemaSubscriber::onEntityTypeDelete in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber::onEntityTypeDelete()
  2. 10 core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber::onEntityTypeDelete()

Reacts to the deletion of the entity type.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type being deleted.

Overrides EntityTypeEventSubscriberTrait::onEntityTypeDelete

File

core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php, line 239

Class

ViewsEntitySchemaSubscriber
Reacts to changes on entity types to update all views entities.

Namespace

Drupal\views\EventSubscriber

Code

public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
  $tables = [
    $entity_type
      ->getBaseTable(),
    $entity_type
      ->getDataTable(),
    $entity_type
      ->getRevisionTable(),
    $entity_type
      ->getRevisionDataTable(),
  ];
  $all_views = $this->entityTypeManager
    ->getStorage('view')
    ->loadMultiple(NULL);

  /** @var \Drupal\views\Entity\View $view */
  foreach ($all_views as $id => $view) {

    // First check just the base table.
    if (in_array($view
      ->get('base_table'), $tables)) {
      $view
        ->disable();
      $view
        ->save();
    }
  }
}