function ReactionRuleConfig::addEvent

Adds an event to the rule configuration.

Parameters

string $event_name: The machine name of the event to add.

array $configuration: (optional) Configuration of the event.

Return value

\Drupal\rules\Core\RulesTriggerableInterface The object instance itself, to allow chaining.

Overrides RulesTriggerableInterface::addEvent

File

src/Entity/ReactionRuleConfig.php, line 256

Class

ReactionRuleConfig
Reaction rule configuration entity to persistently store configuration.

Namespace

Drupal\rules\Entity

Code

public function addEvent(string $event_name, array $configuration = []) {
    if (!$this->hasEvent($event_name)) {
        $event = [
            'event_name' => $event_name,
        ];
        // Only set configuration key if there is configuration.
        // @todo Is this really necessary, as the method parameter has an array
        // type and defaults to the empty array. So $configuration should always
        // be a valid value.
        if (!empty($configuration)) {
            $event['configuration'] = $configuration;
        }
        $this->events[] = $event;
    }
    return $this;
}