SLIDE 1 Everything you ever wanted to know about Drupal 8*
but were too afraid to ask
*conditions apply
SLIDE 2
So you want to start a pony stud
small horses, big hearts
SLIDE 3 Learn Once - Apply Everywhere*
Drupal 8 - in a nutshell
Source: http://www.sxc.hu/photo/784108 *Including outside Drupal
SLIDE 4 Major Architectural Changes
http://www.sxc.hu/photo/207618
SLIDE 5
Don’t be afraid...
SLIDE 6 "If you learnt php from Drupal - Drupal 8 will teach you modern php from a familiar setting"
SLIDE 7 Proudly invented elsewhere
Installed with Composer:
- easyrdf/easyrdf
- symfony2/{various}
- symfony-cmf/routing
- zendframework/zend-feed
- guzzle/http
- doctrine/annotations
- ...
SLIDE 8 Modern PHP
- PHP 5.4+
- Object-oriented PHP
- Classes, Interfaces, Namespaces
- PSR-0, PSR-4
SLIDE 9 Object-Oriented PHP Example
menu_block/lib/Drupal/menu_block/MenuBlockRepository.php
SLIDE 10 Dependency Injection
http://www.sxc.hu/photo/778753
SLIDE 11 Dependency Injection
page_example/lib/Drupal/page_example/ExampleService.php
SLIDE 12 Dependency Injection Container
Symfony2 component Steps:
- 1. Write a class
- 2. Define it as a service in *.services.yml
SLIDE 13 Dependency Injection Container
page_example/page_examples.services.yml
SLIDE 14
Extension points Plugins Modules Services
SLIDE 15 Routing Pages and Forms
http://pixabay.com/en/road-sign-arrows-arrow-direction-64060/
SLIDE 16 Routing Pages and Forms
What does D7 hook_menu really do?
- routes
- default menu items
- local actions
- local tasks
SLIDE 17
D7 Hook Menu
SLIDE 18
D7 Hook Menu
SLIDE 19 Routing Pages
2 easy steps:
- 1. create a PHP class that extends
ControllerBase
- 2. create route definition in module_name.
routing.yml
SLIDE 20
- 2. Create a Controller class
page_example/lib/Drupal/page_example/Controller/PageExampleController. php
SLIDE 21
- 1. Create a route definition
page_example/page_example.routing.yml
SLIDE 22 ControllerBase Goodies
D7 D8 t(‘some text’) $this->t(‘some text’); l(‘title’, $path) $this->l(‘title’, $route_name); url($path) $this->url($route_name); drupal_goto($path) $this->redirect($route_name); global $user $this->currentUser(); variable_get($key) $this->config(‘group’)->get($key); cache_get($key) $this->cache()->get($key); module_exists($m) $this->moduleHandler()->moduleExists ($m)
SLIDE 23
Controller DI Factory Pattern
SLIDE 24 Routing Forms
2 steps:
- 1. create a form class that extends FormBase
- 2. create route definition in module.routing.yml
SLIDE 25
Form Example
SLIDE 26
Form Example
SLIDE 27
What happened to hook_menu()? (sad face)
SLIDE 28
Default Menu Links
hook_menu_link_defaults()
SLIDE 29
Local Actions
module.local_actions.yml
SLIDE 30
Local Tasks
module.local_tasks.yml
SLIDE 31 Other formats?
Leveraging request accept headers
- Ajax controller
- Dialog controller
- REST
Request uri Accept header Response node/1 application/hal+json The node in hal+json node/1 text/html The node page node/1 application/vnd.drupal-modal The node in a modal
SLIDE 32
Routing Documentation
https://drupal.org/node/2122071
SLIDE 33 Configuration System
http://www.sxc.hu/photo/425946
SLIDE 34
Configuration System
variable_{get,set} are gone! Config is stored in yaml files sites/default/files/config_{hash}/{active,staging}
SLIDE 35
Configuration System
$config = \Drupal::config('forum.settings'); $vocabulary = $config->get('vocabulary'); $config->set('vocabulary', 'hooha')->save();
In OO code, inject the @config.factory service
SLIDE 36
Configuration System
system_settings_form() is gone Instead subclass ConfigFormBase Example:
@see \Drupal\system\Form\SiteInformationForm
SLIDE 37
Configuration System
Ctools exportables => Config Entities
SLIDE 38
Configuration System
Unified Entity API including config
$node_type = $storage_controller->create($values); $node_type->save(); $node_type->label(); $node_type->id();
SLIDE 39
Configuration System
Module config imported on install Docs https://drupal.org/node/1667894
SLIDE 40
Configuration System
Deployment workflows Active => Staging => Active
SLIDE 41
Configuration System
Translatable in core Schemas for validation
SLIDE 42
Configuration System
State (Key/Value) API Settings API
SLIDE 43
Plugins
SLIDE 44
Plugins
Learn plugins once - apply it everywhere
SLIDE 45
Plugins
Semi-random magic collection of hooks Real objects and interfaces
SLIDE 46
Drupal 7 Block
function forum_block_info() function forum_block_save() function forum_block_configure() function forum_block_view()
SLIDE 47 Steps:
- 1. Create a new PHP class
- 2. Add some annotations
Drupal 8 Block
SLIDE 48
Blocks
SLIDE 49 Plugins
Advantages:
- Base classes
- Inheritance
- One file per plugin
- Nice. Neat. Tidy.
SLIDE 50 Plugins
So many more Learn Once Apply Everywhere
More: http://bit.ly/1a50ygs
*Stream wrappers still pending Image created with taxedo.com
SLIDE 51
Migrate in core
Sunday 10:30am chx
SLIDE 52 Entities and Fields
http://www.sxc.hu/photo/1433343
SLIDE 53
Entities and Fields
First class objects Swappable classes Common API No more of this crap
$node->field_foo[LANGUAGE_NONE][0]['value']
SLIDE 54 Entities and Fields
New field types
- Link
- Email
- Comment
- Date
- Entity Reference
- Telephone
SLIDE 55
Entities and Fields
Display and form modes Base field consistency Fieldable blocks
SLIDE 56 Entities and Fields
Now plugins:
- Field types
- Field formatters
- Widgets
SLIDE 57 Entities and Fields
Unified API using first-class objects.
D7 : $node->field_foo[LANGUAGE_NONE][0]['value'] D8: Node->title->value Node->field_foo->value
SLIDE 58
Entities and Fields
Info Discovery API
$entity->getPropertyDefinitions() $entity->field_foobar->getFieldDefinition() @see Drupal\Core\Field\FieldDefinitionInterface
SLIDE 59 Frontend
http://twig.sensiolabs.org/
SLIDE 60
Twig
node.tpl.php -> node.html.twig Simple Safe
SLIDE 61
Twig example
SLIDE 62
There’s a session for that...
“Can I TWIG It? Yes, You Can!” Sunday 11:30am mortendk
SLIDE 63
theme() is deprecated
Instead: Return render arrays with a #theme item
SLIDE 64
#theme example
SLIDE 65 drupal_add_js/css() removed
No Javascript will be loaded by default Steps:
- 1. Declare assets with hook_library_info()
- 2. #attach your library in a render array
SLIDE 66
Library Info Hook
SLIDE 67
Coming soon...
https://drupal.org/node/1996238
SLIDE 68
#attached
SLIDE 69
Responsive?
Responsive core themes Responsive admin theme Picture element HTML5
SLIDE 70
More JS Libraries in Core
jQuery UI Touch Punch Backbone, Underscore modernizr domReady html5shiv & classList
SLIDE 71
What else?
Wysiwyg Plugins Tour Edit Backbone, Underscore Toolbar
SLIDE 72
A Tour Of The Tour Module
Sunday 1:30pm nick_schuch
SLIDE 73
Current State
DX Cleanup Criticals and beta blockers
SLIDE 74
Current State
SLIDE 75
Questions?
Lee Rowlands
Senior Drupal Developer PreviousNext @larowlan
Kim Pepper
Technical Director PreviousNext @kim.pepper @kimb0oo