O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Drupal 8

Book Description

Mastering Drupal can lead to a mighty website - discover what Drupal 8 can really do with hidden techniques, best practices, and more!

About This Book

  • The most up-to-date advanced practical guide on Drupal 8 with an in-depth look at all the advanced new features such as authoring, HTML markup, built-in web services, and more
  • If you are looking to dive deep into Drupal 8 and create industry-standard web apps, then this is the ideal book for you
  • All the code and examples are explained in great detail to help you in the development process

Who This Book Is For

This book is ideally suited to web developers, designers, and web administrators who want to dive deep into Drupal. Previous experience with Drupal is a must to unleash the full potential of this book.

What You Will Learn

  • Discover how to better manage content using custom blocks and views
  • Display content in multiple ways, taking advantage of display modes
  • Create custom modules with YAML and Symfony 2
  • Easily translate content using the new multilingual capabilities
  • Use RESTful services and JavaScript frameworks to build headless websites
  • Manage Drupal configuration from one server to another easily

In Detail

Drupal is an open source content management system trusted by governments and organizations around the globe to run their websites. It brings with it extensive content authoring tools, reliable performance, and a proven track record of security. The community of more than 1,000,000 developers, designers, editors, and others have developed and maintained a wealth of modules, themes, and other add-ons to help you build a dynamic web experience.

Drupal 8 is the latest release of the Drupal built on the Symfony2 framework. This is the largest change to the Drupal project in its history. The entire API of Drupal has been rebuilt using Symfony and everything from the administrative UI to themes to custom module development has been affected.

This book will cover everything you need to plan and build a complete website using Drupal 8. It will provide a clear and concise walkthrough of the more than 200 new features and improvements introduced in Drupal core. In this book, you will learn advanced site building techniques, create and modify themes using Twig, create custom modules using the new Drupal API, explore the new REST and Multilingual functionality, import, and export Configuration, and learn how to migrate from earlier versions of Drupal.

Style and approach

This book takes a practical approach with equal emphasis on examples and illustrative screenshots.

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. 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
  2. Developer Workflow
    1. Deciding on a local AMP stack
    2. The role of Composer
      1. Installing Composer locally
      2. Installing Composer globally
      3. Using Composer to create a Drupal project
    3. Speeding up tasks using Drush
      1. Using Drush wrapper
      2. Installing Drush globally
      3. Using Drush to create a Drupal project
    4. A quick look at Drupal Console
      1. Accessing Drupal Console locally
      2. Installing Drupal using Drupal Console
      3. Installing Drupal Console globally
      4. Running a built-in PHP web server
    5. Using Git to manage source code
      1. Installing Git
      2. Configuring Git
      3. Creating a remote repository
      4. Setting up a local repository
      5. Tracking and committing files with Git
      6. Adding a remote origin
      7. Pushing files to the remote repository
    6. Virtualizing an environment
      1. Using Drupal VM as a web starter
    7. Summary
  3. Site Configuration
    1. Assumptions
    2. Exploring Drupal's interface
      1. Managing Drupal
    3. Basic site settings
      1. SITE DETAILS
      2. FRONT PAGE
      3. ERROR PAGES
      4. Performance
        1. Clearing cache
        2. Using Drush to clear cache
        3. Using Drupal Console to clear the cache
    4. Configuration overrides
    5. Using Drush to manage configuration
      1. Listing configuration variables
      2. Retrieving specific variables
      3. Setting configuration variables
    6. Using Drupal Console to manage configuration
      1. Listing configuration variables
      2. Retrieving specific variables
      3. Setting configuration variables
    7. Working with the File system
      1. Managing file paths
      2. Regional settings
      3. Date and time formats
        1. Adding new date formats
    8. Summary
  4. Managing Users, Roles, and Permissions
    1. Assumptions
    2. Exploring People
    3. Managing roles and permissions
      1. What is a role?
      2. Creating a role
      3. Reordering roles
      4. Editing a role
      5. Setting permissions
    4. Working with users
      1. Adding a user
      2. Bulk updating users
    5. Configuring Account settings
      1. CONTACT SETTINGS
      2. ADMINISTRATOR ROLE
      3. REGISTRATION AND CANCELLATION
      4. Managing user fields
        1. Adding fields
      5. Managing form display
    6. Using Drush to manage roles
      1. Listing roles
      2. Creating roles
      3. Deleting roles
      4. Listing permissions
      5. Adding permissions
      6. Removing permissions
    7. Using Drush to manage users
      1. Displaying user information
      2. Assigning roles
      3. Removing roles
      4. Blocking a user
      5. Unblocking a user
      6. Creating user accounts
      7. Cancelling user account
      8. Resetting passwords
      9. Creating a one-time login
    8. Summary
  5. Content Types, Taxonomy, and Comment Types
    1. Assumptions
    2. Exploring Content types
      1. Submission form settings
        1. Preview before submitting
      2. Publishing options
        1. Managing revisions
        2. Reverting content
      3. Display settings
      4. Menu settings
    3. Managing fields
      1. Field settings
    4. Creating custom content types
    5. Managing fields using the Field UI
      1. Deleting fields
        1. Adding new fields
          1. Author field
          2. Teaser field
          3. Content field
          4. Featured Image field
    6. Taxonomy, Vocabularies, and Terms
      1. Adding a vocabulary
        1. Adding terms
      2. Adding a Taxonomy field
    7. Working with Comment types
      1. Adding a Comment type
        1. Adding Comment type field
    8. Working with form and content display
      1. Reordering fields
      2. Modifying Field Widgets
      3. Disabling fields
    9. Using Drupal console to generate dummy content
      1. Creating vocabularies
      2. Creating comments
      3. Creating nodes
    10. Summary
  6. Working with Blocks
    1. Assumptions
    2. Block layout and Regions
      1. Demonstrating block regions
      2. Placing blocks into regions
    3. Block configuration, settings, and visibility
      1. Managing the block title
      2. Using the Contextual menu
      3. Managing visibility settings
        1. Content types restriction
        2. Page restriction
        3. Role restriction
    4. Creating a custom block
      1. Defining the Region
    5. Exploring the Custom block library
      1. Editing custom blocks
      2. Managing block types
      3. Adding fields to blocks
      4. Manage form display
      5. Reordering fields
      6. Modifying field formats
      7. Managing display
    6. Using the Place block interface
    7. Deleting Blocks from Block layout
    8. Summary
  7. Content Authoring, HTML5, and Media
    1. Assumptions
    2. Responsive admin
    3. CKEditor and text formats
      1. Text formats
      2. Toolbar configuration
      3. CKEditor plugin settings and filters
      4. Enabled filters
      5. Filter processing order
      6. Filter settings
    4. Working with images
      1. Image alignment
      2. Image captions
    5. Managing displays
      1. Reordering fields
      2. Controlling labels
      3. Using Field Formatters
        1. Formatting a date field
      4. Managing the Teaser display
    6. Using Better preview
    7. Custom Display settings
      1. Adding a view mode
    8. Image styles
      1. Configuring image styles
      2. Adding image styles
    9. Quick edit
    10. Summary
  8. Understanding Views
    1. Customized lists of contents
      1. View displays
    2. Creating view pages and blocks
      1. Block display
    3. Working with filter criteria and sorting
      1. Rearrange filter criteria
      2. Expose filters
    4. Formatting rows
      1. Row styling
        1. Fields
        2. Content
      2. Field formatting
      3. View formats
        1. Unformatted list
        2. Grid
        3. HTML List
        4. Table
    5. Using advanced features
      1. Relationships
      2. Contextual filters
        1. Display all results for the specified field
        2. Provide a default value
        3. Hide view
        4. Display a summary
        5. Display contents of "No results found"
        6. Display "Access Denied"
      3. Query aggregation
      4. AJAX
    6. Summary
  9. Theming Essentials
    1. Assumptions
    2. What is a theme?
    3. Exploring the Appearance interface
    4. Drupal's core themes
      1. Bartik
      2. Seven
      3. Stark
      4. Classy
    5. Theme states
      1. Installed themes
      2. Uninstalled themes
      3. Default theme
    6. Installing and uninstalling themes
      1. Step one - installing a theme
      2. Step two - uninstalling a theme
    7. Theme settings
      1. Toggling the display of page elements
      2. Logo image settings
      3. Favicon settings
    8. Theme-specific settings
    9. Using prebuilt themes
      1. Folder structure and naming conventions
      2. Managing configuration in Drupal 8
    10. Reviewing the new info.yml file
      1. Metadata
      2. Libraries
      3. Defining a library
      4. Overriding libraries
      5. Extending libraries
      6. Attaching a library
        1. Using Twig to attach a library
        2. Using the preprocess functions to attach a library
    11. Regions
    12. Adding assets to CKEditor
    13. The role of templates in Drupal
      1. How templates work
      2. Where to find templates
    14. Creating a simple theme
      1. Step one - creating a new folder
      2. Step two - create an info file
      3. Step three - create a libraries file
      4. Step four - copy core templates
      5. Step five - include a screenshot
      6. Step six - installing our theme
    15. Summary
  10. Working with Twig
    1. Assumptions
    2. Configuring settings.local.php
      1. Enabling local development services
      2. Disabling render and page cache
      3. Disabling test modules and themes
      4. Enabling Twig debug
    3. Twig fundamentals
      1. Commenting variables
      2. Setting variables
      3. Printing variables
      4. Dumping variables
    4. Filters
    5. Control structures
    6. Functions
    7. Template variables
    8. The role of the theme file in Drupal
      1. Preprocessors and hooks
    9. Working with libraries
      1. Adding assets
      2. Creating a library reference
      3. Including our library
      4. Introducing web fonts
    10. Creating our Jumbotron Block
      1. Step one - Creating a custom block
      2. Step two - Adding a new Jumbotron block
      3. Step three - Placing the Jumbotron block
    11. Page template
    12. Node template
    13. Block template
    14. Field templates
    15. Summary
  11. Extending Drupal
    1. Using Drush
      1. Using Composer
      2. Creating a new module
      3. Understanding configuration and plugins
      4. YAML
      5. Plugins
      6. Annotations
      7. Anatomy of a plugin manager
    2. Working with dependency injection
      1. Services
      2. Creating your own service
        1. Services definition file
          1. abstract
          2. alias
          3. calls
          4. configurator
          5. factory
          6. parent
          7. properties
          8. public
          9. scope
          10. tags
        2. Service implementation
        3. Using your service
    3. Permissions
    4. Routing and menus
      1. Basic routing
        1. Display methods
          1. _form
          2. _entity_view
          3. _entity_list
          4. _entity_form
      2. Handling arguments
      3. Requirements checking
        1. Route matching
          1. _module_dependencies
          2. _method
          3. Parameter matching
        2. Access tests
          1. _permission
          2. _role
          3. _access
          4. _entity_access
          5. _csrf_token
      4. Dynamic routes
      5. Menu links
      6. Local tasks
      7. Local actions
      8. Contextual links
    5. Events and hooks
      1. Using the EventDispatcher
    6. Summary
  12. Working with Forms and the Form API
    1. Creating and managing forms
      1. Creating a new form
      2. Using FormState
      3. Other form types
    2. Exploring the Form API
      1. New Form API types
        1. Color
        2. Details
        3. Dropbutton
        4. HTML tag
        5. Language select
        6. Link
        7. More link
        8. Pager
        9. Path element
        10. Table select
        11. URL
      2. Using AJAX
    3. Summary
  13. RESTful Services
    1. Overview of REST
      1. REST in Drupal 8
      2. HTTP verbs
      3. HAL JSON
      4. Enabling core modules and customizing permissions
      5. Exposing content using Views
    2. Using RESTful endpoints
      1. Displaying content
      2. Unsafe methods and CSRF protection
      3. Creating content
      4. Updating content
      5. Deleting content
    3. Authenticating an application as a Drupal user
      1. Core methods
      2. Contrib methods
    4. Creating REST resources
      1. Using parameters
      2. Using the current user
    5. Summary
  14. Multilingual Capabilities
    1. Enabling core multilingual modules
      1. Language
      2. Interface Translation
      3. Content Translation
      4. Configuration Translation
    2. Installing and configuring languages
    3. Adding language detection
      1. Account administration pages
      2. URL
      3. Session
      4. User
      5. Browser
      6. Selected language
      7. Content language detection
    4. Working with language switching blocks
    5. Translating content
    6. Translating the Drupal admin UI
    7. Using the multilingual API
      1. PHP code
      2. JavaScript
      3. YML files
      4. Annotations
      5. Twig templates
    8. Summary
  15. Configuration Management
    1. Configuration Management files
      1. File format
      2. Schema
        1. Scalar values
        2. Mapping
        3. Sequence
        4. Reusable types
        5. Dynamic type references
      3. Override system
      4. Differences between configuration and state
    2. Using the Config object
    3. Configuration interface
      1. Synchronize configuration
      2. Exporting single configuration
      3. Importing single configuration
      4. Exporting whole site configuration
      5. Importing whole site configuration
    4. Configuration workflow with Drush
    5. Configuration and multilingual sites
      1. Configuration forms
      2. Configuration translation
      3. User interface translation
    6. Summary
  16. Site Migration
    1. Enabling core modules to migrate content
    2. Using Drupal 8's Migrate to handle migrations
    3. Extending migrations with contributed modules
      1. Building a migration process
      2. Creating a migration source
      3. Creating a migration processor
    4. Using Drush to manage migrations
    5. Summary
  17. Debugging and Profiling
    1. Enabling core debugging
      1. Disabling caching
      2. Enabling Twig debugging
      3. Debugging cache performance
    2. Working with Devel and Kint
      1. Installing the Devel module
      2. Printing variables
      3. Printing backtrace
    3. Using the Web Profiler
      1. Installing the Web Profiler module
      2. Request information
      3. Processing timeline
      4. Performance timing
      5. Debugging queries
      6. Debugging Views
    4. Summary