You are here

public function BusinessRulesProcessor::getTriggeredRules in Business Rules 8

Same name and namespace in other branches
  1. 2.x 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 232

Class

BusinessRulesProcessor
Class BusinessRulesProcessor.

Namespace

Drupal\business_rules\Util

Code

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;
}