You are here

public function ReactionRuleStorage::delete in Rules 8.3

Deletes permanently saved entities.

Parameters

array $entities: An array of entity objects to delete.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.

Overrides EntityStorageBase::delete

File

src/Entity/ReactionRuleStorage.php, line 148

Class

ReactionRuleStorage
Storage handler for Reaction Rule configuration entities.

Namespace

Drupal\rules\Entity

Code

public function delete(array $entities) {

  // When a rule is deleted the cache for its event(s) must be invalidated.
  foreach ($entities as $entity) {
    Cache::invalidateTags($entity
      ->getEventNames());
  }

  // After deleting a set of reaction rules, sometimes we may need to rebuild
  // the container, to clean it up, so that the generic subscriber is not
  // registered in the container for the rule events which we do not use
  // anymore. So we do that if there is any change in the registered events,
  // after the reaction rules are deleted.
  $events_before = $this
    ->getRegisteredEvents();
  $return = parent::delete($entities);
  $events_after = $this
    ->getRegisteredEvents();

  // Update the state of registered events and rebuild the container.
  if ($events_before != $events_after) {
    $this->stateService
      ->set('rules.registered_events', $events_after);
    $this->drupalKernel
      ->rebuildContainer();
  }
  return $return;
}