You are here

public static function Rule::preDelete in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Rule.php \Drupal\rng\Entity\Rule::preDelete()
  2. 3.x src/Entity/Rule.php \Drupal\rng\Entity\Rule::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 EntityBase::preDelete

File

src/Entity/Rule.php, line 164

Class

Rule
Defines the event rule entity.

Namespace

Drupal\rng\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $entities) {
  $component_storage = \Drupal::entityTypeManager()
    ->getStorage('rng_rule_component');

  /** @var \Drupal\rng\Entity\RuleInterface $rule */
  foreach ($entities as $rule) {

    // Delete associated rule components.
    $ids = $component_storage
      ->getQuery()
      ->condition('rule', $rule
      ->id())
      ->execute();
    $components = $component_storage
      ->loadMultiple($ids);
    $component_storage
      ->delete($components);
  }
  parent::preDelete($storage, $entities);
}