Everything you ever wanted to know about Drupal 8* but were too - - PowerPoint PPT Presentation

everything you ever wanted to know about drupal 8
SMART_READER_LITE
LIVE PREVIEW

Everything you ever wanted to know about Drupal 8* but were too - - PowerPoint PPT Presentation

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:


slide-1
SLIDE 1

Everything you ever wanted to know about Drupal 8*

but were too afraid to ask

*conditions apply

slide-2
SLIDE 2

So you want to start a pony stud

small horses, big hearts

slide-3
SLIDE 3

Learn Once - Apply Everywhere*

Drupal 8 - in a nutshell

Source: http://www.sxc.hu/photo/784108 *Including outside Drupal

slide-4
SLIDE 4

Major Architectural Changes

http://www.sxc.hu/photo/207618

slide-5
SLIDE 5

Don’t be afraid...

slide-6
SLIDE 6

"If you learnt php from Drupal - Drupal 8 will teach you modern php from a familiar setting"

  • Me, 2014
slide-7
SLIDE 7

Proudly invented elsewhere

Installed with Composer:

  • easyrdf/easyrdf
  • symfony2/{various}
  • symfony-cmf/routing
  • zendframework/zend-feed
  • guzzle/http
  • doctrine/annotations
  • ...
slide-8
SLIDE 8

Modern PHP

  • PHP 5.4+
  • Object-oriented PHP
  • Classes, Interfaces, Namespaces
  • PSR-0, PSR-4
slide-9
SLIDE 9

Object-Oriented PHP Example

menu_block/lib/Drupal/menu_block/MenuBlockRepository.php

slide-10
SLIDE 10

Dependency Injection

http://www.sxc.hu/photo/778753

slide-11
SLIDE 11

Dependency Injection

page_example/lib/Drupal/page_example/ExampleService.php

slide-12
SLIDE 12

Dependency Injection Container

Symfony2 component Steps:

  • 1. Write a class
  • 2. Define it as a service in *.services.yml
slide-13
SLIDE 13

Dependency Injection Container

page_example/page_examples.services.yml

slide-14
SLIDE 14

Extension points Plugins Modules Services

slide-15
SLIDE 15

Routing Pages and Forms

http://pixabay.com/en/road-sign-arrows-arrow-direction-64060/

slide-16
SLIDE 16

Routing Pages and Forms

What does D7 hook_menu really do?

  • routes
  • default menu items
  • local actions
  • local tasks
slide-17
SLIDE 17

D7 Hook Menu

slide-18
SLIDE 18

D7 Hook Menu

slide-19
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
SLIDE 20
  • 2. Create a Controller class

page_example/lib/Drupal/page_example/Controller/PageExampleController. php

slide-21
SLIDE 21
  • 1. Create a route definition

page_example/page_example.routing.yml

slide-22
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
SLIDE 23

Controller DI Factory Pattern

slide-24
SLIDE 24

Routing Forms

2 steps:

  • 1. create a form class that extends FormBase
  • 2. create route definition in module.routing.yml
slide-25
SLIDE 25

Form Example

slide-26
SLIDE 26

Form Example

slide-27
SLIDE 27

What happened to hook_menu()? (sad face)

slide-28
SLIDE 28

Default Menu Links

hook_menu_link_defaults()

slide-29
SLIDE 29

Local Actions

module.local_actions.yml

slide-30
SLIDE 30

Local Tasks

module.local_tasks.yml

slide-31
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
SLIDE 32

Routing Documentation

https://drupal.org/node/2122071

slide-33
SLIDE 33

Configuration System

http://www.sxc.hu/photo/425946

slide-34
SLIDE 34

Configuration System

variable_{get,set} are gone! Config is stored in yaml files sites/default/files/config_{hash}/{active,staging}

slide-35
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
SLIDE 36

Configuration System

system_settings_form() is gone Instead subclass ConfigFormBase Example:

@see \Drupal\system\Form\SiteInformationForm

slide-37
SLIDE 37

Configuration System

Ctools exportables => Config Entities

slide-38
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
SLIDE 39

Configuration System

Module config imported on install Docs https://drupal.org/node/1667894

slide-40
SLIDE 40

Configuration System

Deployment workflows Active => Staging => Active

slide-41
SLIDE 41

Configuration System

Translatable in core Schemas for validation

slide-42
SLIDE 42

Configuration System

State (Key/Value) API Settings API

slide-43
SLIDE 43

Plugins

slide-44
SLIDE 44

Plugins

Learn plugins once - apply it everywhere

slide-45
SLIDE 45

Plugins

Semi-random magic collection of hooks Real objects and interfaces

slide-46
SLIDE 46

Drupal 7 Block

function forum_block_info() function forum_block_save() function forum_block_configure() function forum_block_view()

slide-47
SLIDE 47

Steps:

  • 1. Create a new PHP class
  • 2. Add some annotations

Drupal 8 Block

slide-48
SLIDE 48

Blocks

slide-49
SLIDE 49

Plugins

Advantages:

  • Base classes
  • Inheritance
  • One file per plugin
  • Nice. Neat. Tidy.
slide-50
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
SLIDE 51

Migrate in core

Sunday 10:30am chx

slide-52
SLIDE 52

Entities and Fields

http://www.sxc.hu/photo/1433343

slide-53
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
SLIDE 54

Entities and Fields

New field types

  • Link
  • Email
  • Comment
  • Date
  • Entity Reference
  • Telephone
slide-55
SLIDE 55

Entities and Fields

Display and form modes Base field consistency Fieldable blocks

slide-56
SLIDE 56

Entities and Fields

Now plugins:

  • Field types
  • Field formatters
  • Widgets
slide-57
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
SLIDE 58

Entities and Fields

Info Discovery API

$entity->getPropertyDefinitions() $entity->field_foobar->getFieldDefinition() @see Drupal\Core\Field\FieldDefinitionInterface

slide-59
SLIDE 59

Frontend

http://twig.sensiolabs.org/

slide-60
SLIDE 60

Twig

node.tpl.php -> node.html.twig Simple Safe

slide-61
SLIDE 61

Twig example

slide-62
SLIDE 62

There’s a session for that...

“Can I TWIG It? Yes, You Can!” Sunday 11:30am mortendk

slide-63
SLIDE 63

theme() is deprecated

Instead: Return render arrays with a #theme item

slide-64
SLIDE 64

#theme example

slide-65
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
SLIDE 66

Library Info Hook

slide-67
SLIDE 67

Coming soon...

https://drupal.org/node/1996238

slide-68
SLIDE 68

#attached

slide-69
SLIDE 69

Responsive?

Responsive core themes Responsive admin theme Picture element HTML5

slide-70
SLIDE 70

More JS Libraries in Core

jQuery UI Touch Punch Backbone, Underscore modernizr domReady html5shiv & classList

slide-71
SLIDE 71

What else?

Wysiwyg Plugins Tour Edit Backbone, Underscore Toolbar

slide-72
SLIDE 72

A Tour Of The Tour Module

Sunday 1:30pm nick_schuch

slide-73
SLIDE 73

Current State

DX Cleanup Criticals and beta blockers

slide-74
SLIDE 74

Current State

slide-75
SLIDE 75

Questions?

Lee Rowlands

Senior Drupal Developer PreviousNext @larowlan

Kim Pepper

Technical Director PreviousNext @kim.pepper @kimb0oo