EventDispatcher

Component ID

2774951

Component name

EventDispatcher

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

264

Component created

Component changed

Component body

EventDispatcher provides integration with Symfony EventDispatcher component for Drupal 7.

Module dependencies

Usage

  1. Register EventSubscriber class as a service by any understandable by Service Container method tagging service with event_subscriber tag.
  2. Dispatch an event with:
    
    use SymfonyComponentEventDispatcherEventSubscriberInterface;
    
    class EventSubscriber implements EventSubscriberInterface {
    
      public function methodName($event, $eventName, $eventDispatcher) {
        // Do something...
      }
      
      public static function getSubscribedEvents() {
        return array('eventName' => array('methodName'));
      }
    
    }
    
    $event = new Event();
    $ed = Drupal::service('event_dispatcher');
    $ed->dispatch('eventName', $event);