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.
3. 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?
4. How Did We Get Here?
A brief overview of Drupal customization history
5. 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
6. 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
7. Drupal 8 with Symfony
• Event subscribers for hooks
• Dependency injection for core
services
• Portable code in open
ecosystem
• Fully unit testable
• Upgrade at will
8. Why Use an Event Dispatcher?
I had this with hooks before all this Symfony nonsense
9. 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
10. 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
11. 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
12. How To Use the Event Dispatcher
This better not be just some sales job
13. 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.
14. Example > 1000 Slides
https://github.com/aenglander/drupal-event-dispatcher-example
15. This Is Only The Beginning
Well, we can only hope
16. Build A Better Module
• More modular
• Loosely coupled
• Highly extensible
• Highly configurable
• Bulletproof
• Utilizing external libraries to
build better and faster
17. 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
18. 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