Everything you ever wanted to know about Drupal 8* but were too afraid to ask *conditions apply
So you want to start a pony stud small horses, big hearts
Drupal 8 - in a nutshell Learn Once - Apply Everywhere* Source: http://www.sxc.hu/photo/784108 *Including outside Drupal
Major Architectural Changes http://www.sxc.hu/photo/207618
Don t be afraid...
"If you learnt php from Drupal - Drupal 8 will teach you modern php from a familiar setting" - Me, 2014
Proudly invented elsewhere Installed with Composer: easyrdf/easyrdf symfony2/{various} symfony-cmf/routing zendframework/zend-feed guzzle/http doctrine/annotations...
Modern PHP PHP 5.4+ Object-oriented PHP Classes, Interfaces, Namespaces PSR-0, PSR-4
Object-Oriented PHP Example menu_block/lib/drupal/menu_block/menublockrepository.php
Dependency Injection http://www.sxc.hu/photo/778753
Dependency Injection page_example/lib/drupal/page_example/exampleservice.php
Dependency Injection Container Symfony2 component Steps: 1. Write a class 2. Define it as a service in *.services.yml
Dependency Injection Container page_example/page_examples.services.yml
Extension points Plugins Modules Services
Routing Pages and Forms http://pixabay.com/en/road-sign-arrows-arrow-direction-64060/
Routing Pages and Forms What does D7 hook_menu really do? routes default menu items local actions local tasks
D7 Hook Menu
D7 Hook Menu
Routing Pages 2 easy steps: 1. create a PHP class that extends ControllerBase 2. create route definition in module_name. routing.yml
2. Create a Controller class page_example/lib/drupal/page_example/controller/pageexamplecontroller. php
1. Create a route definition page_example/page_example.routing.yml
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) ($m) $this->modulehandler()->moduleexists
Controller DI Factory Pattern
Routing Forms 2 steps: 1. create a form class that extends FormBase 2. create route definition in module.routing.yml
Form Example
Form Example
What happened to hook_menu()? (sad face)
Default Menu Links hook_menu_link_defaults()
Local Actions module.local_actions.yml
Local Tasks module.local_tasks.yml
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
Routing Documentation https://drupal.org/node/2122071
Configuration System http://www.sxc.hu/photo/425946
Configuration System variable_{get,set} are gone! Config is stored in yaml files sites/default/files/config_{hash}/{active,staging}
Configuration System $config = \Drupal::config('forum.settings'); $vocabulary = $config->get('vocabulary'); $config->set('vocabulary', 'hooha')->save(); In OO code, inject the @config.factory service
Configuration System system_settings_form() is gone Instead subclass ConfigFormBase Example: @see \Drupal\system\Form\SiteInformationForm
Configuration System Ctools exportables => Config Entities
Configuration System Unified Entity API including config $node_type = $storage_controller->create($values); $node_type->save(); $node_type->label(); $node_type->id();
Configuration System Module config imported on install Docs https://drupal.org/node/1667894
Configuration System Deployment workflows Active => Staging => Active
Configuration System Translatable in core Schemas for validation
Configuration System State (Key/Value) API Settings API
Plugins
Plugins Learn plugins once - apply it everywhere
Plugins Semi-random magic collection of hooks Real objects and interfaces
Drupal 7 Block function forum_block_info() function forum_block_save() function forum_block_configure() function forum_block_view()
Drupal 8 Block Steps: 1. Create a new PHP class 2. Add some annotations
Blocks
Plugins Advantages: Base classes Inheritance One file per plugin Nice. Neat. Tidy.
Plugins So many more Learn Once Apply Everywhere More: http://bit.ly/1a50ygs *Stream wrappers still pending
Migrate in core Sunday 10:30am chx
Entities and Fields http://www.sxc.hu/photo/1433343
Entities and Fields First class objects Swappable classes Common API No more of this crap $node->field_foo[language_none][0]['value']
Entities and Fields New field types Link Email Comment Date Entity Reference Telephone
Entities and Fields Display and form modes Base field consistency Fieldable blocks
Entities and Fields Now plugins: Field types Field formatters Widgets
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
Entities and Fields Info Discovery API $entity->getpropertydefinitions() $entity->field_foobar->getfielddefinition() @see Drupal\Core\Field\FieldDefinitionInterface
Frontend http://twig.sensiolabs.org/
Twig node.tpl.php -> node.html.twig Simple Safe
Twig example
There s a session for that... Can I TWIG It? Yes, You Can! Sunday 11:30am mortendk
theme() is deprecated Instead: Return render arrays with a #theme item
#theme example
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
Library Info Hook
Coming soon... https://drupal.org/node/1996238
#attached
Responsive? Responsive core themes Responsive admin theme Picture element HTML5
More JS Libraries in Core jquery UI Touch Punch Backbone, Underscore modernizr domready html5shiv & classlist
What else? Wysiwyg Plugins Tour Edit Backbone, Underscore Toolbar
A Tour Of The Tour Module Sunday 1:30pm nick_schuch
Current State DX Cleanup Criticals and beta blockers
Current State
Questions? Lee Rowlands Senior Drupal Developer PreviousNext @larowlan Kim Pepper Technical Director PreviousNext @kim.pepper @kimb0oo