Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Infinite Wonder of the Symfony Event Dispatcher

Drupla 8, and its Symfony core, open the doors to a wonderous world of options when it comes to customizing Drupal. Long dead are the copy and modify days of the Drupal of old. This is the time of the event dispatcher.

In this session, you will learn about the Symfony event dispatcher and how Drupal utilizes the event dispatcher in its request processing. The main focus will be on utilizing event subscribers to affect the behavior of Drupal with a small footprint and minimal development. Drupal 8 provides some amazing opportunities to inject customization into its core processes with minimal risk and side effects. The core of this ability lies with the Synfony event dispatcher. This session is intended for intermediate to advanced users wishing to modify the behavior of Drupal 8.

  • Login to see the comments

  • Be the first to like this

The Infinite Wonder of the Symfony Event Dispatcher

  1. 1. The Infinite Wonder of the Symfony Event Dispatcher Adam Englander
  2. 2. Why Are You Here? • Drupal developer trying to learn about Symfony? • Symfony developer trying to learn about Drupal? • PHP developer learning about Drupal? • Cool presentation title? • None of the above?
  3. 3. How Did We Get Here? A brief overview of Drupal customization history
  4. 4. The before time…the long, long ago• Copy core or template code to site code • Hack around for what you need • Beam with the pleasure of customizing Drupal • Break things unknowingly • Only patch when required because you changed core
  5. 5. Drupal 5-7• Copy core and customize for true core functionality • Use hooks for node events • Use global functions to access core data and transforms • Upgrade fairly simply as long as the hooks or global functions did not change • Unit tests? Copyright 2006 Daniel Jaeger - Creative Commons - Attribution Share Alike
  6. 6. Drupal 8 with Symfony • Event subscribers for hooks • Dependency injection for core services • Portable code in open ecosystem • Fully unit testable • Upgrade at will
  7. 7. Why Use an Event Dispatcher? I had this with hooks before all this Symfony nonsense
  8. 8. Highly Modular Code • Build your modules and templates like building blocks • Reusable code in an open ecosystem • Use proven libraries inside and outside the Drupal ecosystem • Highly testable code at the unit level
  9. 9. Highly Decoupled Code • Injects services in the Dependency Injection Container • Should not require intimate knowledge of core systems only event name and event class • Allows for mix and match of components providing services based on events
  10. 10. Highly Extensible Code • Modular code is extensible • Logic can be extracted services • Logic can be extracted outside the Drupal environment • Services can register and trigger their own events for extensibility
  11. 11. How To Use the Event Dispatcher This better not be just some sales job
  12. 12. Oversimplified Overview 1. Create a service in your module that implements the EventSubscriberInterface. 2. Write handlers for those events in your service. 3. Returned a list of handled events with the handlers and their priority with the service’s getSubscribedEvents method. 4. Register the service with the tag event_subscriber in your services.yml file.
  13. 13. Example > 1000 Slides https://github.com/aenglander/drupal-event-dispatcher-example
  14. 14. This Is Only The Beginning Well, we can only hope
  15. 15. Build A Better Module • More modular • Loosely coupled • Highly extensible • Highly configurable • Bulletproof • Utilizing external libraries to build better and faster
  16. 16. Build A Better Drupal • Create pre and post events for everything • Get away from copy core and modify • Utilize more non-Drupal libraries for more functionality • Accelerate platform growth
  17. 17. My Contact Info • adam@launchkey.com • @adam_englander on Twitter • #aenglander on Freenode • http://spkr8.com/t/66771 • https://github.com/aenglander/drupal-event- dispatcher-example
  18. 18. Please rate my talk… http://spkr8.com/t/66771 Thanks!

×