You are here

protected function RngEntityModel::postSaveRngRule in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/RngEntityModel.php \Drupal\rng\RngEntityModel::postSaveRngRule()
  2. 3.x src/RngEntityModel.php \Drupal\rng\RngEntityModel::postSaveRngRule()

Update rule scheduler after a rule entity is saved.

Parameters

\Drupal\rng\RuleInterface $entity: An RNG rule entity.

1 call to RngEntityModel::postSaveRngRule()
RngEntityModel::hook_entity_postsave in src/RngEntityModel.php
React to Drupal `hook_entity_insert` or `hook_entity_update` hooks.

File

src/RngEntityModel.php, line 189

Class

RngEntityModel
Enforces RNG model relationships.

Namespace

Drupal\rng

Code

protected function postSaveRngRule(RuleInterface $entity) {
  if (isset($entity->original)) {

    // Don't continue if rule status didn't change.
    if ($entity
      ->isActive() == $entity->original
      ->isActive()) {
      return;
    }
  }
  foreach ($entity
    ->getConditions() as $condition) {
    if ('rng_rule_scheduler' == $condition
      ->getPluginId()) {

      // Create, update, or delete the associated rule scheduler entity if the
      // rule status has changed.

      /** @var \Drupal\rng\Plugin\Condition\RuleScheduler $plugin */
      $plugin = $condition
        ->createInstance();
      $plugin
        ->updateRuleSchedulerEntity();
      $plugin_configuration = $plugin
        ->getConfiguration();
      $condition
        ->setConfiguration($plugin_configuration);
      $condition
        ->save();
    }
  }
}