Drupal 8 logo in outer space

A Gentle Introduction to Drupal 8

With the release of Drupal 8 drawing ever nearer, it’s important to know what will change — and what will stay the same — with our favorite CMS.

I decided to test out its shiny new bells and whistles by setting up side-by-side vanilla installs of D7 and D8 on my Windows box. Here are five things I learned in the process.

System Requirements & Installation

After downloading the Drupal 8 core files and setting up my database, I visited my site to perform the installation process and was dismayed to see a WSOD. It turns out D8 requires PHP 5.5.9 or higher, which is newer than what my version of XAMPP included. Fortunately, upgrading XAMPP to version 3.2.1 was easy, if a bit time-consuming. After this minor hiccup, the installation process proceeded smoothly, and was almost identical to what I’m used to seeing in D7.

At the end, I was greeted by a slightly updated version of the familiar Bartik theme, sporting a coolly redesigned responsive toolbar and tooldrawer. The “Modules” button has been renamed “Extend,” and the infamous Overlay module for administrative screens has been replaced by a “Back to site” button in the toolbar.

Changes to Core Modules

Drupal 8 core includes several new modules out of the box. Some, like Views, have been contrib modules up until now and had to be installed each time a site was spun up (and when was the last Drupal site you saw that didn’t use Views?). Others are new additions to Drupal.

Views behaves almost exactly as it always has, with a couple minor UI tweaks to improve workflow (such as duplicating a display AS another type).

I was excited to see that Drupal 8 core now includes CKEditor, allowing for out-of-the-box WYSIWYG text editing in fields of type Text (formatted, long) and Text (formatted, long, with summary). The text editor can be changed on a per-text-format basis courtesy of the new Text Editor module.

Also included is native support for responsive images and viewport breakpoints via the new Breakpoint and Responsive Image modules. Responsive Image is disabled by default, but when turned on allows you to define multiple images to use for different breakpoints. The image choices are rendered using the img tag’s srcset attribute.

Another new core module that will excite users is Quick Edit, a contrib module in D7, which allows on-page editing of individual entity fields. The new version of Quick Edit is robust and has been well thought out for all D8’s new field types (detailed below).

There are several core modules in Drupal 7 that have been removed from Drupal 8. Many of them, including OpenID, PHP Filter, and Poll, will still be available as contrib modules. Others, such as Blog, Number, and Overlay, have been made redundant by new features or paradigms.

One semantic change that confused me at first was enabling and disabling modules. These tasks, previously accomplished on the same screen, have been split onto two tabs and renamed “Install” and “Uninstall.” This change in terminology is tricky, because it overloads the word “Install” with two meanings. Installing a new module from the List tab copies its files to the modules directory, but then to enable the module requires checking its checkbox and clicking “Install” again. Likewise, “uninstalling” (disabling) a module does not remove the module’s directory or files.

Overall, Drupal 8’s module core has been discreetly expanded with a carefully chosen palette of new functionality. Of course, creating a real, functioning D8 site at present would be difficult or impossible, as many key contrib modules have not yet been ported over — but this will quickly change as more people start to explore the system.

New Field Types

Along with its richer module base, Drupal 8 also includes several new field types for content.

These are:

  • Comments
    Comments are no longer a base option on new content types. Instead, you must explicitly add a Comments field to achieve the same functionality.
  • Date
    Creates a date-time or date-only field complete with a nice HTML5 calendar dropdown. Date display can be formatted using PHP date formats.
  • Email
    Creates an HTML5 email field which provides an extra layer of in-browser validation. Field display can be either as a mailto: link or the email address text.

  • Link
    Creates a URL paired with link text. Can be constrained to accept only internal or external links.
  • Other
    Perhaps most exciting of all, the Other field type is an entity reference to a specific entity type. (Content and User types are shortcuts to entries in the same list of choices.) The Other type incorporates the previous Taxonomy term reference. In addition to terms, nodes and users, you can also reference blocks, menus, views, and many more entity types, including more abstract ones such as RDF mappings
  • Text (formatted)
    There are three new formatted text field types. The long types use the native CKEditor WYSIWYG editor by default.

These new field types will certainly cut down on the amount of ad hoc configuration, coding, and contrib module installation necessary for most sites.

Changes to Directory Structure

Drupal 8’s directory structure is inherently more site-centric than its predecessors. Priorities have been flip-flopped: site specific code and files have been moved to the top-level directory, and core files have been tucked away in their own folder. I know in my case this will reduce the likelihood of inadvertently hacking core. But users migrating sites from D7 will have to pay special attention to the contents of the top-level directories.

So for those of you wondering where the precious /sites/all directory has gone, here’s a quick summary of the remappings:

Drupal 7 Drupal 8
/modules /core/modules
/profiles /core/profiles
/themes /core/themes
/sites/all/modules /modules
/sites/all/profiles /profiles
/sites/all/themes /themes
/sites/all/libraries /libraries

Changes to Theming & Configuration

Twig

Remember when you took the time to learn PHP? Well, don’t forget it, because you’ll still need it to write modules — but you’ll no longer need it in your template files. The theming system in Drupal 8 is now based on the Twig template engine instead of PHPTemplate. Twig is oriented toward better separation of concerns… model and controller logic is kept out of the template (although Twig does support the same control structures you’re used to). If you have experience with Django or Liquid, Twig may look familiar to you, and it has ample online documentation.

An example of code output using PHP Template:

My Site

The same code in Twig:

My Site

Template files now live in their own folder within your theme (e.g. /themes/yourtheme/templates), and have the .html.twig suffix instead of .tpl.php. They are named using the same convention as in Drupal 7; e.g. field--node--field-tags.html.twig. Creating new template files still requires a cache clear, just as before. Curiously, the Views module does not seem to report theming information as it did in D7, but the template files should be named the same as they would have been in D7.

Symfony2

Twig is part of the Symfony2 framework, which is another major change in Drupal 8. You may notice in your Drupal 8 installation a large number of .yml files. These are configuration files for themes and modules, written in a language called YAML. YAML is a very simple markup language similar to a pared-down version of XML, and Symfony parses it into PHP arrays for Drupal to use.

By default, site and module configuration is still stored in the database to optimize performance. However, in my opinion, one of the most exciting features of Drupal 8 is its built-in configuration management (CMI). This means that it has the powerful native ability to import and export configuration settings, either globally or at a granular level. This is done via YAML snippets. In previous versions, moving configuration around between different instances of a site was a pain point that was partially remedied by the use of the Features module. However, this approach was error-prone and enlisted Features to solve problems far beyond what it was originally meant for. With the advent of CMI in Drupal 8, configuration management should be exponentially easier, and the Features module can go back to doing what it’s good at: managing bundles of functionality.

In conclusion

In conclusion, the latest version of Drupal continues to live up to its reputation of being powerful, flexible, minimal, and well thought out. By building on open-source technologies that have stood the test of time, Drupal 8 solves many problems that were inherent in previous versions and opens the way for more rapid site development and deployment.

Thank you to Dries and the thousands of contributors to Drupal 8!

A bit about Peter:

Peter has been designing and coding websites since 2003, and working with Drupal since 2010.
Peter is an accompanist for his city's children's chorale and enjoys bike riding, good food, photography, branding design, and being active in his church.