You are here

public static function View::preDelete in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Entity/View.php \Drupal\views\Entity\View::preDelete()

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and before invoking the delete hook.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides ConfigEntityBase::preDelete

File

core/modules/views/src/Entity/View.php, line 403

Class

View
Defines a View configuration entity class.

Namespace

Drupal\views\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $entities) {
  parent::preDelete($storage, $entities);

  // Call the remove() hook on the individual displays.

  /** @var \Drupal\views\ViewEntityInterface $entity */
  foreach ($entities as $entity) {
    $executable = Views::executableFactory()
      ->get($entity);
    foreach ($entity
      ->get('display') as $display_id => $display) {
      $executable
        ->setDisplay($display_id);
      $executable
        ->getDisplay()
        ->remove();
    }
  }
}