public function RuleScheduler::updateRuleSchedulerEntity in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Plugin/Condition/RuleScheduler.php \Drupal\rng\Plugin\Condition\RuleScheduler::updateRuleSchedulerEntity()
- 3.x src/Plugin/Condition/RuleScheduler.php \Drupal\rng\Plugin\Condition\RuleScheduler::updateRuleSchedulerEntity()
Create, update, or delete the associated rule scheduler entity.
Depending on if it needs to exist.
1 call to RuleScheduler::updateRuleSchedulerEntity()
- RuleScheduler::submitConfigurationForm in src/
Plugin/ Condition/ RuleScheduler.php - Form submission handler.
File
- src/
Plugin/ Condition/ RuleScheduler.php, line 124
Class
- RuleScheduler
- Schedules rule execution based on the configured date.
Namespace
Drupal\rng\Plugin\ConditionCode
public function updateRuleSchedulerEntity() {
$rule_scheduler = $this
->getRuleScheduler();
$rule_component_id = $this
->getRuleComponentId();
$rule_component = $rule_component_id ? RuleComponent::load($rule_component_id) : NULL;
$rule = $rule_component ? $rule_component
->getRule() : NULL;
$rule_active = $rule instanceof RuleInterface ? $rule
->isActive() : FALSE;
if ($rule_active) {
if (!$rule_scheduler) {
// Create the scheduler entity if it doesn't exist.
$rule_scheduler = RuleSchedule::create([
'component' => $this
->getRuleComponentId(),
]);
$rule_scheduler
->save();
$this->configuration['rng_rule_scheduler'] = $rule_scheduler
->id();
}
// Mirror the date into the scheduler.
if ($rule_scheduler) {
$rule_scheduler
->setDate($this->configuration['date']);
$rule_scheduler
->save();
}
}
else {
// Delete the rule scheduler if it is not in the queue already.
if ($rule_scheduler && !$rule_scheduler
->getInQueue()) {
$rule_scheduler
->delete();
}
}
}