The Infinite Wonder of the Symfony Event Dispatcher
-
Upload
adam-englander -
Category
Internet
-
view
141 -
download
0
Transcript of The Infinite Wonder of the Symfony Event Dispatcher
The Infinite Wonder of the Symfony Event Dispatcher
Adam Englander
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?
How Did We Get Here?A brief overview of Drupal customization history
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
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
Drupal 8 with Symfony
• Event subscribers for hooks
• Dependency injection for core services
• Portable code in open ecosystem
• Fully unit testable
• Upgrade at will
Why Use an Event Dispatcher?I had this with hooks before all this Symfony nonsense
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
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
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
How To Use the Event DispatcherThis better not be just some sales job
Oversimplified Overview1. 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.
Example > 1000 Slides
https://github.com/aenglander/drupal-event-dispatcher-example
This Is Only The BeginningWell, we can only hope
Build A Better Module• More modular
• Loosely coupled
• Highly extensible
• Highly configurable
• Bulletproof
• Utilizing external libraries to build better and faster
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
My Contact Info• [email protected]
• @adam_englander on Twitter
• #aenglander on Freenode
• http://spkr8.com/t/66771
• https://github.com/aenglander/drupal-event-dispatcher-example
Please rate my talk…http://spkr8.com/t/66771
Thanks!