Drupal is a registered trademark of Dries Buytaert
Search API Solr 4.3.13 Minor update available for module search_api_solr (4.3.13). Search API Solr 4.3.12 Minor update available for module search_api_solr (4.3.12). IntelligenceBank DAM Connector 4.1.4 Minor update available for module intelligencebank (4.1.4). IntelligenceBank DAM Connector 5.2.3 Minor update available for module intelligencebank (5.2.3). Soccerbet 1.1.14 Minor update available for module soccerbet (1.1.14). Mautic Audiences 1.0.0 Initial release available for module mautic_audiences (1.0.0)! Commerce Order Amend 1.0.0 Initial release available for module commerce_order_amend (1.0.0)! AI Provider moonshot (Kimi) 1.2.1 Minor update available for module ai_provider_moonshot (1.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Content Translation Redirect Module content_translation_redirect crossed 1,000 active installs.

This module allows developers to register event listeners in Drupal using Symfony's #[AsEventListener] attribute. This provides a more streamlined way to subscribe to and react to events within your Drupal site, similar to how it's done in Symfony. It offers an alternative to the traditional Drupal service tagging method.

The "AsEventListener" module enables developers to use the Symfony attribute #[AsEventListener] to register event subscribers/listeners.

To register an event subscriber in Drupal you need to create a service and tag
it as event_subscriber. See Subscribe to and dispatch events on drupal.org.

Symfony however defines the attribute #[AsEventListener] so developers are able to register classes or single methods as event listeners. This module brings this feature to Drupal.
It is planned to add this feature to Drupal core. Until #3376163 is fixed, this module provides a way to make use of it now.

Usage

To make use of this module you need to setup classes or methods as event
listeners using #[AsEventListener]. The classes needs to be in namespace Drupal\[...]\EventListener to be registered automatically.

Example

<?php

namespace Drupal\my_custom_module\EventListener;

#[AsEventListener(event: RoutingEvents::ALTER)]
class TestEventListener {

  /**
   * Use the class directly as event listener.
   *
   * @param \Drupal\Core\Routing\RouteBuildEvent $event
   *   The dispatched event.
   */
  public function __invoke(RouteBuildEvent $event): void {
    // Do something.
  }

}

This will add this class as event listener for RoutingEvents::ALTER so every time this event is dispatched, TestEventListener::__invoke() is called.

See Defining Event Listeners with PHP Attributes for details about how to use #[AsEventListener].

Activity

Total releases
3
First release
Apr 2026
Latest release
2 months ago
Releases (12 mo)
3 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Release date
1.0.2 Stable Apr 20, 2026
1.0.1 Stable Apr 20, 2026
1.0.0 Stable Apr 15, 2026