Last updated December 9, 2021
Events in Drupal allow various system components to interact and communicate with one another while remaining independent, or decoupled. They are one of the ways that module developers can alter or extend Drupal without modifying existing code. (Other ways include Plugins, Hooks, and Services). The system consists of an event dispatcher which is used to trigger a known event at a specific point during code execution. It also consists of a pattern for subscribing in order to be notified whenever an event is triggered by the dispatcher so that your custom code can react.
The event system is built on the Symfony event dispatcher component and is an implementation of the Mediator design pattern.
Example tasks
- Subscribe to an existing event in order to react with custom logic whenever the event occurs
- Dispatch a new event when critical actions happen in your code, giving other components the option to react
Confidence
The event system in Drupal is unlikely to change for a while. Expect contributed modules to start dispatching events in place of invoking hooks for some types of interactions. Resources labeled with Drupal 8 should also apply to Drupal 9.
Drupalize.Me resources