Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu,...

36
Drupal 8 eming 1 Zakiya Khabir drupal.org/u/zakiya twitter.com/zakiyadesigns Code: github.com/zakiya/d8-theming-camp-demo

Transcript of Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu,...

Page 1: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Drupal 8 Theming

1

Zakiya Khabir drupal.org/u/zakiya twitter.com/zakiyadesigns

Code: github.com/zakiya/d8-theming-camp-demo

Page 2: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Questions?

2

Page 3: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

D7 < D8 Small Core Changes

• Views, Admin Menu, Breakpoints, Date, Entity

Reference, Link, CKeditor, Migrate, Block Menus (light),

Responsive Image, multilingual support, and fieldable

blocks all in core

• Backbone.js, Underscore.js, and Modernizr are in core

• No JQuery or CSS loads by default.

3

Page 4: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

D7 < D8 Big Core Changes

• Configuration Management

• Using Twig templating engine

• No more IE 6, 7, and 8 support

4

Page 5: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

D7 < D8 Gotchas

• drush cr not drush cc all

• /themes instead of /sites/all/themes

• /modules instead of sites/all/modules

5

Page 6: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Local Dev Setup Get your Drupal

• Find latest dev or beta on d.o

• drupal.org/node/3060/release

• Download and install on your favorite _AMP stack

6

Page 7: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Local Dev Setup Performance Settings

• By default css, js and html are cached

• Disable caching through UI at /config/development/performance

• Or • Copy sites/example.settings.local.php to settings.local.php

• See /sites/example.settings.local.php) • Uncomment these lines in /default/settings.php :

if (file_exists(__DIR__ . 'settings.local.php')) { include __DIR__ . ‘/settings.local.php'; }

• drush cr when done!

7

Page 8: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

THEME.info.yml8

Basic Declarations

Page 9: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Logo • If logo is called logo.svg and put

in root folder Drupal will auto-detect

• logo.png or logo.gif can be added via Drupal UI

9

Page 10: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Screenshot • screenshot.png placed in root will be

auto-detected • or declare in THEME.info.yml

10

Page 11: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Declare Base Theme11

Page 12: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Theme Features 12

Page 13: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Regions • Theme will work with no regions • Declare regions in

THEME.info.yml

13

Page 14: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Modify Core/Module CSS

14

Page 15: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Remove Core/Module CSS

15

Page 16: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Adding Stylesheets 16

Page 17: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Adding Libraries • drupal.org/developing/api/8/assets

17

Page 18: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Declare Library • Edit THEME.info.yml

18

Page 19: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Add CSS and JS 19

Page 20: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Optionally Include JQuery

20

Page 21: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Other Ways to include assets

• To versioning existing libraries: hook_library_info_alter()

See: api.drupal.org

• To add assets conditionally: hook_preprocess_page(&$vars) { $vars['#attached']['library'][] = 'core/modernizr'; }

• OR hook_page_attachments_alter(&$page) { if ($conditions) {

$page['#attached']['library'][] = ‘core/jquery';

}

See: drupal.org/theme-guide/8/assets

21

Page 22: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Time

22

Page 23: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Why Twig • Secure • Separate business logic from display • Faster, smarter templating engine • Supported/used beyond Drupal

23

Page 24: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Debug • Change twig.config: debug: true

in services.yml

24

Page 25: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Templates • 141 Twig templates* • To override, place in *.html.twig in theme

folder • Don’t forget to drush cr

25

*$ find path/to/core/modules -name *.html.twig ! -path "*test*"

Page 26: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Code Basics • To print {{my_variable}}

• To comment {# Drupaling b. #}

• To operate {% if title %} …

26

Page 27: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Code Extras • Translate function (filter) {{ 'Home'|t }}

• Check_plain {{ title|striptags }}

• See others at • undpaul.de/en/blog/2013/02/26/

theming-drupal-8-twig-part-2• drupal.org/node/1918824

27

Page 28: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Code Extras Reuse Templates

28

Page 29: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Code Extras Twig Blocks

29

Page 30: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Preprocess • THEME.theme replaces template.php

30

Page 31: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig {{dump}}*

• {{ dump()}}

• {{ dump(my_variable) }}

• drupal.org/node/1906780 *Might get WSOD due to memory issues

31

Page 32: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Devel + Kint

32

Page 33: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Twig Documentation

• twig.sensiolabs.org/documentation

33

Page 34: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Responsive • breakpoints in core

drupal.org/documentation/modules/breakpoint

• THEME.breakpoints.yml • picture in core

34

Page 35: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Other things • Drupal settings for use in js • Classy module • Initialize Image Style Settings in

theme https://www.drupal.org/node/2356753

• No HOOK_process

35

Page 36: Drupal 8 eming - Stanford University · D7 < D8 Small Core Changes • Views, Admin Menu, Breakpoints, Date, Entity Reference, Link, CKeditor, Migrate, Block Menus (light), Responsive

Gimme feedback

36

Zakiya Khabir drupal.org/u/zakiya twitter.com/zakiyadesigns

Code: github.com/zakiya/d8-theming-camp-demo