function EventComponentResolver::getMultiple

Overrides RulesComponentResolverInterface::getMultiple

File

src/ComponentResolver/EventComponentResolver.php, line 45

Class

EventComponentResolver
Resolves components that hold all reaction rules for a given event.

Namespace

Drupal\rules\ComponentResolver

Code

public function getMultiple(array $event_ids) {
    // @todo Improve this by adding a custom expression plugin that clones
    // the state after each rule, such that added variables added by one rule
    // are not interfering with the variables of another rule.
    $results = [];
    foreach ($event_ids as $event_id) {
        $action_set = $this->expressionManager
            ->createActionSet();
        // Only load active reaction rules - inactive (disabled) Rules should
        // not be executed, so we shouldn't even load them.
        $configs = $this->entityStorage
            ->loadByProperties([
            'events.*.event_name' => $event_id,
            'status' => TRUE,
        ]);
        if ($configs) {
            // We should only produce $results if there are loaded reaction rules.
            foreach ($configs as $config) {
                $action_set->addExpressionObject($config->getExpression());
            }
            $results[$event_id] = RulesComponent::create($action_set);
        }
    }
    return $results;
}