function GenericEventSubscriber::getSubscribedEvents

File

src/EventSubscriber/GenericEventSubscriber.php, line 71

Class

GenericEventSubscriber
Subscribes to Symfony events and maps them to Rules events.

Namespace

Drupal\rules\EventSubscriber

Code

public static function getSubscribedEvents() {
    // Register this listener for every event that is used by a reaction rule.
    $events = [];
    $callback = [
        'onRulesEvent',
        100,
    ];
    // If there is no state service there is nothing we can do here. This static
    // method could be called early when the container is built, so the state
    // service might not always be available.
    if (!\Drupal::hasService('state')) {
        return [];
    }
    // Since we cannot access the reaction rule config storage here we have to
    // use the state system to provide registered Rules events. The Reaction
    // Rule storage is responsible for keeping the registered events up to date
    // in the state system.
    // @see \Drupal\rules\Entity\ReactionRuleStorage
    $state = \Drupal::state();
    $registered_event_names = $state->get('rules.registered_events');
    if (!empty($registered_event_names)) {
        foreach ($registered_event_names as $event_name) {
            $events[$event_name][] = $callback;
        }
    }
    return $events;
}