function ReactionRuleStorage::save
Overrides ConfigEntityStorage::save
File
-
src/
Entity/ ReactionRuleStorage.php, line 113
Class
- ReactionRuleStorage
- Storage handler for Reaction Rule configuration entities.
Namespace
Drupal\rules\EntityCode
public function save(EntityInterface $entity) {
// We need to get the registered events before the rule is saved, in order
// to be able to check afterwards if we need to rebuild the container or
// not.
$events_before = $this->getRegisteredEvents();
$return = parent::save($entity);
$events_after = $this->getRegisteredEvents();
// Update the state of registered events.
$this->stateService
->set('rules.registered_events', $events_after);
// After the reaction rule is saved, we may need to rebuild the container,
// otherwise the reaction rule will not fire. We do that only if the
// registered events are different.
ksort($events_before);
ksort($events_after);
if ($events_before !== $events_after) {
$this->drupalKernel
->rebuildContainer();
}
// When a reaction rule is saved (either added, updated or enabled/disabled)
// the cache for its event(s) needs to be invalidated. These tags are set in
// the RulesComponentRepository class.
//
// @see \Drupal\rules\Engine\RulesComponentRepository::getMultiple()
Cache::invalidateTags($entity->getEventNames());
return $return;
}