public function BusinessRulesProcessor::getTriggeredRules in Business Rules 2.x
Same name and namespace in other branches
- 8 src/Util/BusinessRulesProcessor.php \Drupal\business_rules\Util\BusinessRulesProcessor::getTriggeredRules()
Check if there is a Business rule configured for the given event.
Parameters
\Drupal\business_rules\Events\BusinessRulesEvent $event: The event.
string $trigger: The trigger.
Return value
array Array of triggered rules.
1 call to BusinessRulesProcessor::getTriggeredRules()
- BusinessRulesProcessor::process in src/
Util/ BusinessRulesProcessor.php - Process rules.
File
- src/
Util/ BusinessRulesProcessor.php, line 250
Class
- BusinessRulesProcessor
- Class BusinessRulesProcessor.
Namespace
Drupal\business_rules\UtilCode
public function getTriggeredRules(BusinessRulesEvent $event, $trigger) {
$entity_type = $event
->getArgument('entity_type_id');
$bundle = $event
->getArgument('bundle');
$rule_names = $this->storage
->listAll('business_rules.business_rule');
$rules = $this->storage
->readMultiple($rule_names);
$triggered_rules = [];
// Dispatch a event before check the triggered rules.
$this->eventDispatcher
->dispatch('business_rules.before_check_the_triggered_rules', $event);
foreach ($rules as $rule) {
$rule = new BusinessRule($rule);
if ($rule
->isEnabled() && $trigger == $rule
->getReactsOn() && ($entity_type == $rule
->getTargetEntityType() || empty($rule
->getTargetEntityType())) && ($bundle == $rule
->getTargetBundle() || empty($rule
->getTargetBundle()))) {
$triggered_rules[$rule
->id()] = $rule;
}
}
// Dispatch a event after check the triggered rules.
$this->eventDispatcher
->dispatch('business_rules.after_check_the_triggered_rules', $event);
return $triggered_rules;
}