July 2017
Intermediate to advanced
456 pages
11h 32m
English
An event listener is first and foremost just another type of service. This gives you the advantage of being able to isolate your event listener and use dependency injection. This gives you an ease of unit testing that the normal hook system cannot provide. You can create an event listener manually or use the Drupal Console to do by it by running drupal generate:event:subscriber and following the prompts:

The Drupal console updated the mastering_drupal_8.services.yml file to add the new service with the following:
mastering_drupal_8.event_subscriber: class:Drupal\mastering_drupal_8\EventSubscriber\MasteringDrupal8EventSubscriber ...
Read now
Unlock full access