Drupal 8:

The Awesome Parts

Christopher Bloom, @illepic

Frontend Lead, Phase2 Technology
(Ask questions whenever, this is a discussion)

Goals

A quick walkthrough of the modern approaches to building Drupal 8 sites

Required

  • Command line, for real

  • Git

Composer

  • A Drupal site is made up (usually) many modules
  • Composer provides industry standard dependency management
  • Pull in libraries, Drupal modules/themes/distributions
  • Ensure all dependencies work together
  • Drupal Composer project
  • DrupalVM (next slide)

 

https://getcomposer.org/

Drupal VM

  • A fully built Drupal environment based on Ansible and Composer
  • Requires local install of VirtualBox 5.1.6, Vagrant 1.8.7, Ansible 2
  • A simple



     and you have a working Drupal 8 site at (dashboard.drupalvm.dev)

 

https://www.drupalvm.com/

Warning: https://github.com/geerlingguy/drupal-vm/issues/981

cp default.drupal.composer.json drupal.composer.json
cp default.config.yml config.yml
vagrant up

Composer + DrupalVM

http://docs.drupalvm.com/en/latest/

 

Workflow:

  • Edit drupal.composer.json
  • Run vagrant provision
  • Drupal is updated with the latest modules pulled from drupal.org
  • DO NOT COMMIT YOUR CONTRIB DRUPAL MODULES!

Drupal Console

https://drupalconsole.com/

 

Workflow:

  • Soon to be Drush replacement
  • Interact and query Drupal in extremely powerful ways
  • Clear caches, dump/import config (more on this later)
  • GENERATE themes, modules, migrations. See this cheatsheet.
  • DrupalVM comes with Drupal Console, so:
vagrant ssh
cd /var/www/drupalvm/drupal
console status

Drupal Console Generate

  • Generate almost anything in Drupal:
  • drupal generate:theme - Theme basics
  • drupal generate:module - Scafold out theme
  • drupal generate:plugin:block - A quick, on-off custom block

 

Side note:

YAML. All configuration in Drupal 8 is stored in YAML. Whitespace matters, representations of arrays objects (see demo)

Configuration Management!

https://www.drupal.org/docs/8/configuration-management/managing-your-sites-configuration


Workflow:

  • Common development environments are local, dev, stage, production
  • Configure your site on local, make content types, fields, settings
  • Export configuration (in sites/default/files/config_)
  • Commit all these new changes, push to repo
  • The next level of server (local -> dev) git pulls in this config and simply imports
  • Much, much less reliance on Features (discussion here)

Twig theming is amazing

https://www.drupal.org/docs/8/theming/twig

 

  • Yet another Symfony component, very powerful templating language
  • First, enable Twig debugging:





    Now all output contains full information on where it originated.
# sites/default/services.yml:

parameters:
  twig.config:
    debug: true # originally false

Twig theming (continued)

themename.theme:

 

 

 

 

node.html.twig:

/**
 * Implements hook_preprocess_node().
 */
function charles_preprocess_node(array &$variables) {
  $variables['charles_var'] = t('Hello class');
  $variables['charles_array'] = ['charles1', 'charles2', 'charles3'];
}
<ul>
  {% for charles in charles_array %}
    <li>{{ charles }}</li>
  {% endfor %}
</ul>

Let's explore further

  • Many new modules in core (Views, Better Formats, WYSIWYG, etc)
  • View modes on everything
  • Everything is fieldable (even taxonomy!)
  • Breakpoints/responsive features on the backend!
  • Much better multilingual
  • REST services in core

Drupal 8: The Awesome Parts

By Christopher Bloom

Drupal 8: The Awesome Parts

  • 2,316