Drupal 8 Development Cookbook - Second Edition

Book description

Over 60 hands-on recipes that get you acquainted with Drupal 8's features and help you harness its power

About This Book

  • Discover the enhanced content authoring experience that comes with Drupal 8 and how to customize it
  • Take advantage of the broadened multilingual and tools of the new version to provide an internationalized website
  • This step-by-step guide will show you how to deploy from development, staging, and production of a website with Drupal 8's brand new configuration management system

Who This Book Is For

The audience of the Drupal 8 Cookbook have been using Drupal and are ready to get a grasp of what to expect in Drupal 8. They have worked with Drupal as site builders, back-end developers, and front-end developers and are eager to see what awaits when they start using Drupal 8. This book will be a resource that allows them to get started and have a reference to building new applications with Drupal.

What You Will Learn

  • Extend Drupal through contributed or custom modules and themes
  • Develop an internationalized website with Drupal's multilingual tools
  • Integrate third-party front-end and back-end libraries with Drupal
  • Turn Drupal into a web services provider using REST
  • Create a mobile-first responsive Drupal application
  • Run SimpleTest and PHPUnit to test Drupal
  • Understand the plugin system that powers many of Drupal 8's new APIs to extend its functionality
  • Get to grips with the mechanics of the configuration management system and the ability to import and export site configuration

In Detail

Began as a message board, Drupal today is open source software maintained and developed by a community of over 1,000,000 users and developers. Drupal is used by numerous local businesses to global corporations and diverse organizations all across the globe. With Drupal 8’s exciting features it brings, this book will be your go-to guide to experimenting with all of these features through helpful recipes.

We’ll start by showing you how to customize and configure the Drupal environment as per your requirements, as well as how to install third-party libraries and then use them in the Drupal environment. Then we will move on to creating blocks and custom modules with the help of libraries. We will show you how to use the latest mobile-first feature of Drupal 8, which will help you make your apps responsive across all the major platforms. This book will also show you how to incorporate multilingual facilities in your sites, use web services and third-party plugins with your applications from inside Drupal 8, and test and deploy your apps.

Style and approach

This practical, recipe-based book will provide you with actionable techniques and methods to improve your existing Drupal development skills.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Up and Running with Drupal 8
    1. Introduction
    2. Installing Drupal
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Creating a database user and a database
        2. Database prefixes
        3. Downloading and installing with Drush
        4. Using Composer to create a Drupal site
        5. Security updates
      5. See also
    3. Using a distribution with Drupal
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Makefiles
        2. Installing with Drush
        3. Using Composer
      4. See also...
    4. Installing modules and themes
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Discovering modules and themes
        2. Module installation
        3. Theme installation
      4. There's more...
        1. Installing a module or theme using Composer
        2. Installing a module with Drush
        3. Uninstalling a module
      5. See also
    5. Using multisites in Drupal 8
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Security concerns
        2. Domain aliases
      5. See also...
    6. Tools for setting up an environment
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Acquia Dev Desktop
        2. XAMPP + Bitnami
        3. Kalabox
      5. See also
    7. Running tests - Simpletest and PHPUnit
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Is run-tests a shell script?
        2. Running tests without Drupal installed
        3. Running specific tests
        4. PhpStorm - Drupal Test Runner
        5. DrupalCI
      5. See also...
  3. The Content Authoring Experience
    1. Introduction
    2. Configuring the WYSIWYG editor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Filter module
        2. Improved links
        3. CKEditor plugins
      5. See also
    3. Adding and editing content
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Save as draft
        2. Pathauto
        3. Bulk moderation
      5. See also
    4. Creating a menu and linking content
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Managing a contents menu link from its form
    5. Providing inline editing
      1. How to do it...
      2. How it works...
      3. There's more...
        1. The outside-in approach
    6. Creating a custom content type
      1. How to do it...
      2. How it works...
    7. Applying new Drupal 8 core field types
      1. Getting ready
      2. How to do it...
        1. Link
        2. The Email field
        3. The Telephone field
        4. The Date field
        5. The Entity Reference field
      3. How it works...
      4. There's more...
        1. Upcoming updates
        2. Views and Entity Reference
      5. See also
    8. Customizing the form display of a node
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Managing form display modes
        2. Programmatically providing a default to hidden form items
      4. See also
    9. Customizing the display output of a node
      1. How to do it...
      2. How it works...
  4. Displaying Content through Views
    1. Introduction
    2. Listing content
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Views in Drupal core initiative
        2. Views and displays
        3. Format style plugins - style and row
        4. Using the Embed display
      5. See also
    3. Editing the default admin interfaces
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Exposed versus non-exposed
        2. Filter identifiers
        3. Overriding routes with Views
    4. Creating a block from a View
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Exposed forms as blocks
      5. See also
    5. Utilizing dynamic arguments
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Previewing with contextual filters
        2. Displaying as a tab on the user page
        3. Altering the page title
        4. Validation
        5. Multiple and exclusion
    6. Adding a relationship in a View
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Relationships provided by entity reference fields
        2. Relationships provided through custom code
        3. Using aggregation and views.
    7. Providing an Entity Reference result View
      1. How to do it...
      2. How it works...
      3. See also
  5. Extending Drupal
    1. Introduction
    2. Creating a module
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Module namespaces
        2. Module discovery locations
        3. Defining a package group
        4. Module dependencies
        5. Specifying the module's version
      4. See also...
    3. Defining a custom page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Parameters in routes
        2. Validating parameters in routes
        3. Route requirements
        4. Providing dynamic routes
        5. Altering existing routes
      5. See also
    4. Defining permissions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Restrict access flag for permissions
        2. Defining permissions programmatically
        3. Checking whether a user has permissions
    5. Providing the configuration on the installation or update
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Configuration subdirectories
        2. Modifying the existing configuration on installation
      5. See also
    6. Creating an event subscriber
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Using dependency injection
      4. See also
    7. Using Features 3.0
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Suggested feature modules
        2. Features bundles
        3. Managing the configuration state of Features
      4. See also
  6. Frontend for the Win
    1. Introduction
    2. Creating a custom theme based on Classy
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Theme screenshots
        2. Themes, logos, and favicons
        3. Base themes and shared resources
        4. CKEditor style sheets
      4. See also
    3. Using the new asset management system
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. CSS groups
        2. Library asset options
        3. Library dependencies
        4. Overriding and extending other libraries
        5. Using a CDN or external resource as a library
        6. Manipulating libraries from hooks
        7. Placing JavaScript in the header
      5. See also
    4. Twig templating
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Security first
        2. Theme hook suggestions
        3. Debugging template file selection and hook suggestions
        4. The Twig logic and operators
      5. See also
    5. Using the Breakpoint module
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Caveat for providing breakpoints from themes
        2. Accessing breakpoints programmatically
        3. Multipliers
      5. See also
    6. Using the Responsive Image module
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Performance first delivery
        2. Removing picturefill polyfill
      5. See also
  7. Creating Forms with the Form API
    1. Introduction
    2. Creating a form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Form element definitions
        2. The form state
        3. The form cache
      5. See also
    3. Using new HTML5 elements
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Specific element properties
        2. Creating new elements
      5. See also
    4. Validating form data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Multiple validation handlers
        2. Accessing multidimensional array values
        3. Element validation methods
    5. Processing submitted form data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Multiple submit handlers
      5. See also
    6. Altering other forms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding additional validate handlers
        2. Adding additional submit handlers
  8. Plug and Play with Plugins
    1. Introduction
    2. Creating blocks using plugins
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Altering blocks
        2. Block settings forms
        3. Defining access to a block
      5. See also
    3. Creating a custom field type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Altering field types
        2. Defining whether a field is empty
      5. See also
    4. Creating a custom field widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Field widget settings and summary
      5. See also
    5. Creating a custom field formatter
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Formatter settings and summary
      5. See also
    6. Creating a custom plugin type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Specifying an alter hook
        2. Using a cache backend
        3. Accessing plugins through the manager
      5. See also
  9. Multilingual and Internationalization
    1. Introduction
    2. Translating administrative interfaces
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Manually installing language files
        2. Checking translation status
        3. Exporting translations
        4. Interface translation permissions
        5. Using interface translation to customize default English strings
        6. Interface text language detection
        7. Providing translations for a custom module
      5. See also
    3. Translating configuration
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Altering configuration translation info definitions
        2. Translating views
      5. See also
    4. Translating content
      1. Getting ready
      2. How to do it...
      3. How it works
      4. There's more...
        1. Flagging translations as outdated
        2. Translating content links
        3. Defining translation handlers for entities
      5. See also
    5. Creating multilingual views
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Translating exposed form items and filters
        2. Translating display and row format items
        3. Translating page display menu items
      5. See also
  10. Configuration Management - Deploying in Drupal 8
    1. Introduction
    2. Importing and exporting configurations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Configuration dependencies
        2. Saving to a YAML file for a module's configuration installation
        3. Configuration schemas
      5. See also
    3. Synchronizing site configurations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Universally Unique Identifier
        2. A synchronization folder
        3. Installing a configuration from a new site
    4. Using command-line workflow processes
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Drush config-pull
        2. Using the Drupal Console
        3. Editing the configuration from the command line
        4. Exporting a single configuration item
        5. Using version control and command-line workflow
      5. See also
    5. Updating and installing new module configurations
      1. How to do it...
      2. How it works...
      3. There's more...
        1. The Configuration Development module
      4. See also
  11. The Entity API
    1. Introduction
    2. Creating a configuration entity type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Available data types for schema definitions
      5. See also
    3. Creating a content entity type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using the AdminHtmlRouteProvider provider
        2. Making the collection route a local task tab
      5. See also
    4. Creating a bundle for a content entity type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Provide action links for adding new bundles
      5. See also
    5. Implementing custom access control for an entity
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Controlling access to entity fields
      5. See also
    6. Providing a custom storage handler
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Utilizing a different storage backend for an entity
      5. See also
    7. Creating a route provider
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. The Entity API module provides additional providers
      5. See also
  12. Off the Drupalicon Island
    1. Introduction
    2. Implementing and using a third-party JavaScript library
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Best practices for handling external libraries
      5. See also
    3. Implementing and using a third-party CSS library
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Implementing and using a third-party PHP library
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  13. Web Services
    1. Introduction
    2. Enabling RESTful interfaces
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using _format instead of the Accept header
        2. RestResource plugin to expose data through RESTful Web Services
        3. Rate limiting your API
        4. Using the HAL format
        5. See also
    3. Using POST to create data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using HAL and understanding _links requirements
        2. Working with images
        3. Using Cross-Site Request Forgery tokens
      5. See also
    4. Using PATCH to update data
      1. Getting ready
      2. How to do it...
      3. How it works…
    5. Using Views to provide custom data sources
      1. How to do it…
      2. How it works
      3. There's more...
        1. Controlling the key name in JSON output
        2. Controlling access to RESTful Views
    6. Authentication
      1. Getting ready
      2. How to do it
      3. How it works
      4. There's more…
        1. Authentication provider services
        2. Page cache request policies and authenticated Web service requests
        3. The IP Authentication provider
      5. See also
    7. Using JSON API
      1. Getting ready
      2. How to do it
      3. How it works...
      4. There's more...
        1. Paginating, filtering, and sorting requests
        2. Installing the JSON API Extras module
        3. Changing the API path prefix
        4. Disabling and enhancing returned entity fields
        5. Contenta CMS
      5. See also
  14. The Drupal CLI
    1. Introduction
    2. Rebuilding cache in Drupal Console or Drush
      1. How to do it…
      2. How it works…
      3. See also
    3. Using Drush to interact with the database
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
        1. Using gzip with sql-dump
        2. Using Console to interact with the database
    4. Using Drush to manage users
      1. How to do it…
      2. How it works…
      3. There's more…
        1. Advanced user-login use cases
        2. Using Drupal Console
    5. Scaffolding code through Console
      1. Getting ready
      2. How to do it…
      3. How it works…
    6. Making a Drush command
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
        1. Specifying the level of Drupal's bootstrap
      5. See also
    7. Making a Console command
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
        1. Using a Console command to create entities
      5. See also

Product information

  • Title: Drupal 8 Development Cookbook - Second Edition
  • Author(s): Matt Glaman
  • Release date: September 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788290401