You are here

public static function ShortcutSet::preDelete in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/Entity/ShortcutSet.php \Drupal\shortcut\Entity\ShortcutSet::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/shortcut/src/Entity/ShortcutSet.php, line 92

Class

ShortcutSet
Defines the Shortcut set configuration entity.

Namespace

Drupal\shortcut\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $entities) {
  parent::preDelete($storage, $entities);
  foreach ($entities as $entity) {
    $storage
      ->deleteAssignedShortcutSets($entity);

    // Next, delete the shortcuts for this set.
    $shortcut_ids = \Drupal::entityQuery('shortcut')
      ->condition('shortcut_set', $entity
      ->id(), '=')
      ->execute();
    $controller = \Drupal::entityTypeManager()
      ->getStorage('shortcut');
    $entities = $controller
      ->loadMultiple($shortcut_ids);
    $controller
      ->delete($entities);
  }
}