Aaron Bauman
Alex Rhodes
Navigating Drupal 8 APIs for Drupal 7 developers
Project overview
Pull (Queue API)
node_load()
is now
\Drupal::service('entity_type.manager')
->getStorage('node')
->load()
This is... verbose. Why is it better?
Controllers, storage, access, permissions
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()
This is more concise. Why is this better?
hook_cron_queue_info
is now
Plugin\QueueWorker
Why is this better?
module_invoke_all()
is now
\Drupal::service('event_dispatcher')->dispatch()
Drupal 7
+ Salesforce client encapsulated in a class
- php file contains 3 different classes
+ internal methods are atomized
- return values are not reliable
Drupal 8
+ PSR-4 enforces namespacing, class hierarchy
+ New Classes for return values
+ type-hinting whenever possible
+ Salesforce Exception classes
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"
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!
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.
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
Aaron Bauman
aaron@messageagency.com
drupal.org/u/aaronbauman