Updating your modules to Drupal 8:
Salesforce Suite
Who are we?
Aaron Bauman
- 8+ years Drupal developer & module maintainer
- aaron@messageagency.com
- drupal.org/u/aaronbauman
Alex Rhodes
- 7 year Drupal developer
- rhodes@messageagency.com
- drupal.org/u/ironsizide
Why are we here?
Navigating Drupal 8 APIs for Drupal 7 developers
- Entity & Entity Storage API
- Plugin API
- Events Dispatcher
- Queue API
- Building a REST client for Salesforce API
- Route Subscriber, dynamic routing, and route alterations (hook_menu_alter) *
What is Salesforce?
Project overview
- Mappings (Plugin API, Entity Storage)
-
Pull (Queue API)
- Push (Queue API, custom)
- Push/Pull Events (Events Dispatcher)
- Salesforce REST API Client
Entity & Entity Storage
node_load()
is now
\Drupal::service('entity_type.manager')
->getStorage('node')
->load()
Entity & Entity Storage
This is... verbose. Why is it better?
- Extensibility
- Dependability
- Testability
Entity & Entity Storage
Controllers, storage, access, permissions
- Annotations
- hook_schema - gone
- giant arrays - gone (sort of)
- normalized entity definitions
- proper object model
- major functionality "for free," e.g. views
Entity & Entity Storage
Plugin API
hook_my_module_new_api_info
+ module_invoke_all + hook_my_module_new_api_data
+ hook_my_module_new_api_CALLBACK_FUNCTION
is now
\Drupal::service('my_module.plugin_manager')
->getDefinitions()
Plugin API
This is more concise. Why is this better?
- Extensibility
- Dependability
- Testability
Plugin API
Queue API
hook_cron_queue_info
is now
Plugin\QueueWorker
Queue API
Why is this better?
- Extensibility
- Dependability
- Testability
Queue API
Events API
module_invoke_all()
is now
\Drupal::service('event_dispatcher')->dispatch()
Events API
Salesforce REST API client
Drupal 7
+ Salesforce client encapsulated in a class
- php file contains 3 different classes
+ internal methods are atomized
- return values are not reliable
Salesforce REST API client
Drupal 8
+ PSR-4 enforces namespacing, class hierarchy
+ New Classes for return values
+ type-hinting whenever possible
+ Salesforce Exception classes
Salesforce REST API client
Key Takeaways
Lower barrier to implementing new APIs
- Extend a class, rather than copy-pasting and re-writing
- Plugin API and Annotations reduce overhead and time to ship
- Lots of previously hard/tedious things we now get "for free"
Key Takeaways
OOP, finally
- Reliable arguments and return values make devs happy
- Traits make it easy to reuse components across inheritance, extensibility, and interfaces
- Consistent expectations for all objects. No more stdClass, yay!
Key Takeaways
Early architecture decisions are important
- Naming conventions are crucial, and tedious to change
- Writing tests early (or full TDD) is faster than writing tests for a large, existing stack
- Dependency injection and encapsulation, every time
- Not sure the best way to do something?
Look for a pattern in core.
Key Takeaways
Navigating and learning D8 can be tedious
- dozens of nesting levels and wrappers
- Namespacing means class names are no longer unique
- keep a copy of "core.services.yml" handy at all times
- use a smart IDE, or a good documentation tool like Dash
- be ready to search d.o documentation, changelogs, and issue queue for "the D8 way" to do things
- Examples module implements dozens of different APIs
Thank You
Aaron Bauman
aaron@messageagency.com
drupal.org/u/aaronbauman
SFD8
By aaronbauman
SFD8
- 1,450