You are previewing Drupal 8 Development Cookbook.
O'Reilly logo
Drupal 8 Development Cookbook

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

This book is for those have been working with Drupal, such as site builders, back-end developers, and front-end developers, and who are eager to see what awaits when they start using Drupal 8

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 recent release and the 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 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. It will get you started with Drupal 8 and will be your reference guide to building new applications with Drupal.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Drupal 8 Development Cookbook
    1. Table of Contents
    2. Drupal 8 Development Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why Subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. 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. Security updates
        5. See also
      3. Using a distribution
        1. How to do it…
        2. How it works…
        3. There's more…
          1. Makefiles
          2. Installing with Drush
        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 with Drush
          2. 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
        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 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 Simpletest without Drupal installed
          3. Running specific tests
          4. DrupalCI
        5. See also…
    9. 2. 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. 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…
      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 e-mail field
          3. The Telephone field
          4. Date
          5. The Entity Reference
        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…
    10. 3. 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. There's more…
          1. View arguments
        4. See also
    11. 4. 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 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. Using Features 2.x
        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
    12. 5. 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 stylesheets
        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
    13. 6. 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
    14. 7. 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
    15. 8. 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
    16. 9. 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. Using the filesystem for configuration storage
        1. How to do it…
        2. How it works…
        3. There's more…
          1. Deprecated for Drupal 9
        4. See also
    17. 10. 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. Simplifying base field definitions using the Entity module
          3. The entity type's admin permission
          4. 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 add generation
          2. Providing a collection route
        5. See also
    18. 11. 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. 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
      5. Using Composer manager
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
          1. Updating the Stack/Cors recipe
        5. See also
    19. 12. 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. Soft dependency on the HAL module
          2. RestResource plugin to expose data through RESTful Web Services
          3. The REST UI module
          4. Rate limiting your API
        5. See also
      3. Using GET to retrieve data
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
          1. Using _format instead of the Accept header
        5. See also
      4. Using POST to create data
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
          1. Understanding available _links requirements
          2. Working with images
          3. Using Cross-Site Request Forgery tokens
        5. See also
      5. Using PATCH to update data
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      6. 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 of RESTful Views
          3. Add a URL formatter for the image field
        4. See also
      7. Authentication
        1. Getting ready
        2. How to do it…
        3. There's more…
          1. Authentication provider services
          2. Page cache request policies and authenticated web service requests
          3. IP Authentication Provider
        4. See also
    20. 13. The Drupal CLI
      1. Introduction
      2. Rebuilding cache in Console or Drush
        1. How to do it…
        2. How it works…
      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
        5. See also
      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
    21. Index