function ViewsEntitySchemaSubscriber::onEntityTypeDelete

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

Overrides EntityTypeEventSubscriberTrait::onEntityTypeDelete

File

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

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.