28,99 €
Learning Drupal can be challenging because of its robust, extensible, and powerful capability for digital experiences, making it difficult for beginners to grasp and use it for application development. If you’re looking to break into Drupal with hands-on knowledge, this Drupal 10 Masterclass is for you.
With this book, you’ll gain a thorough knowledge of Drupal by understanding its core concepts, including its technical architecture, frontend, backend, framework, and latest features. Equipped with foundational knowledge, you’ll bootstrap and install your first project with expert guidance on maintaining Drupal applications. Progressively, you’ll build applications using Drupal’s core features such as content structures, multilingual support, users, roles, Views, search, and digital assets. You’ll discover techniques for developing modules and themes and harness Drupal’s robust content management through layout builder, blocks, and content workflows. The book familiarizes you with prominent tools such as Git, Drush, and Composer for code deployments and DevOps practices for Drupal application management. You’ll also explore advanced use cases for content migration and multisite implementation, extending your application’s capabilities.
By the end of this book, you’ll not only have learned how to build a successful Drupal application but may also find yourself contributing to the Drupal community.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 345
Veröffentlichungsjahr: 2023
Drupal 10 Masterclass
Build responsive Drupal applications to deliver custom and extensible digital experiences to users
Adam Bergstein
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Alok Dhuri
Publishing Product Manager: Uzma Sheerin
Book Project Manager: Deeksha Thakkar
Senior Editor: Nisha Cleetus
Technical Editor: Rajdeep Chakraborty
Copy Editor: Safis Editing
Indexer: Tejal Soni
Production Designer: Joshua Misquitta
Business Development Executive: Puneet Kaur
DevRel Marketing Coordinators: Deepak Kumar and Mayank Singh
First published: December 2023
Production reference: 1221123
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK
ISBN 978-1-83763-310-4
www.packtpub.com
To my girls, Leah and Nora, for their learning, to help their generation, and to show you can chase your dreams.
– Adam Bergstein
Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers testing sandboxes to Drupal community members. He has also worked for both–agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Mike Herchel, author of Chapter 19, is the primary developer behind Drupal’s default theme (called Olivero), as well as a maintainer of Drupal core’s CSS subsystem. He’s on a crusade to improve Drupal’s front-end developer experience for those new to the Drupal ecosystem. If you have feedback on this, or thoughts on what’s hard to accomplish, please reach out to him at [email protected]. The work on this chapter was traded for beer, and in fact, if you find Mike at a local DrupalCamp, you can typically get him to do core development in exchange for beer.
Rachel Lawson has been working in open source communities, primarily Drupal, for the last 17 years. Rachel has held diverse roles across education, defense, and pharmaceuticals, learning many of her community skills as a mentor, core mentoring coordinator of the Drupal open source project, and community liaison for the Drupal Association. She has most recently had the opportunity to take many of the good practices in open source into international development with the Digital Impact Alliance at the United Nations Foundation.When not working, Rachel can usually be found planning or enjoying her next overland adventure on her motorbike – 26 countries in 4 continents so far, where’s next?
This part covers all of the basics for Drupal. You will get an overview on what Drupal does at a high level followed by understanding the differences between core, modules, and themes. A review of the supporting infrastructure and Drupal's primary architectural components are covered. The open source community and their practices are reviewed. And, the part finishes by reviewing the new features of Drupal 10.
This part has the following chapters:
Chapter 1, What is Drupal?Chapter 2, Drupal Core, Modules, and ThemesChapter 3, Infrastructure and Overview of Technical ArchitectureChapter 4, Drupal CommunityChapter 5, What’s New in Drupal 10Drupal is a popular content management system (CMS) for building websites, web applications, and digital experiences. With such flexibility, it can be difficult to define exactly what Drupal is. This chapter explores that question in depth to clarify its identity, purpose, and objective.
The goal of this chapter is to provide a solid foundation that we will build upon in the more practical, hands-on chapters found later in this book. Learning basic concepts and understanding the community are essential for anyone who wants to work with Drupal.
In this chapter, we will explore the following topics:
What is a CMS?Framework and extensibilityBasic conceptsPopular case studiesA CMS, in its simplest form, is a tool to create, update, maintain, and present content. This was historically for websites, but now, they’re commonly used for digital experiences given the rise of omnichannel content delivery. The foundations of the web started with servers delivering static HTML files over the internet. Tools that abstracted technical complexities in building HTML, such as Macromedia Dreamweaver, allowed non-technical audiences to author websites without knowing how to code. HTML files would be modified on someone’s personal computer and subsequently pushed up to a web server through protocols such as FTP or SFTP. A CMS abstracts both the coding and the file-based operations to enhance the capabilities of a system. Many CMSs also handle content delivery given that managing content has evolved to address more complex use cases with specific access controls, editorial reviews, and more.
The modern CMS has evolved to serve several popular use cases. Many eCommerce websites manage products, pricing, and promotions through a CMS where the system manages shopping carts, users, and payment transactions. Social networks, such as Twitter and Facebook, harness content management capabilities to deliver user-specific, innovative digital experiences.
Enterprise CMS systems must account for much more than just browser-based content delivery, which explains Drupal’s evolution. Omnichannel capabilities often allow a CMS to serve as a central content store while allowing the same content to be served across any channel from a website, app on your phone, a notification stream, and more. A CMS is now viewed as a major enabler for an effective digital strategy spanning simple websites for small businesses to a highly integrated content store for major corporations. Over time, Drupal has added the features and extensibility necessary to be a platform that enterprises adopt.
CMS systems began by managing content published on basic websites. Today, applications such as Drupal have evolved to be able to dynamically deliver content through many channels and manage data across a vast amount of enterprise capabilities. Recognizing this evolution helps explain Drupal’s position in the space of CMS solutions as an enabler not just for simple website use cases, but far more.
I once heard Drupal described as analogous to Lego building blocks in that Lego blocks of all shapes and sizes; what can be created is limited only by your imagination. Many people have attempted to define what Drupal is. While a clear definition may help people understand when and how to adopt Drupal, if Drupal is of interest to them, or if Drupal can help them deliver a specific solution effectively, this is not a constructive way to understand what Drupal is.
Drupal is a tool. What is delivered with the tool can vary drastically. That is why the Lego analogy works. With Lego blocks, you can build a house, a car, a Star Wars figure… practically anything. Lego blocks empower a builder to create what they want to create. Often, people want a clear definition of Drupal. Is it a house, a car, or a Star Wars figure? No – it is a tool that helps you create the digital experiences you want to build. While I understand a desire to define what Drupal can be used for, looking at Drupal in this manner can be significantly limiting.
Drupal grew in popularity as a CMS. Drupal empowered site builders by offering a user interface for configuring structured content and serving that structured content as rendered HTML. Imagine a system that can be used to both create and deliver websites. Drupal offers that. Content is stored persistently by authors and then rendered for site visitors dynamically. Drupal is an application developed in PHP that leverages a database storage backend. Older CMSs simply managed static files, whereas Drupal is a functional system that can be programmed to manage content. Page requests do not correspond to static files; instead, they are dynamically processed by Drupal. The system interprets a URL, parameters, and sessions to deliver a unique, generated result back to the browser at the time the request was made. Some requests get content, others serve the user interface to manage content. Drupal handles all of that.
However, Drupal can do much more than basic content management. Out of the box, the core of Drupal delivers many features that allow it to be configured for conventional content management. This includes structured content, WYSIWYG, media/static file management, caching, rendering content displays, API-based content delivery, and more. However, Drupal also comes with a highly extensible framework that allows for it to be customized. Given Drupal is open source, community members have contributed their customizations back to the open-source community as projects that can be downloaded and installed on any Drupal application.
The goal of this book is to show how Drupal, its out-of-the-box features, and contributed projects can be built and configured to deliver amazing digital experiences. Like a large box of Lego blocks, the aim of this book is not to define exactly what can be built but to show you how to use the tool to accomplish a large number of potential outcomes. What you do is only bound by your imagination.
Drupal’s core delivers two fundamental parts of the application: a frontend web application and a backend administrative system. Both are delivered through the Drupal application, which can be accessed from a web browser differentiated based on the request. Common backend paths, such as the user login page “user” and administrative console “admin,” help Drupal differentiate requests.
Conceptually, Drupal’s backend performs tasks and retrieves information about the Drupal system. Tasks change based on the access granted to the user. However, common tasks include performing content updates, configuring Drupal system settings, and managing modules. Useful information, such as Drupal’s system status page, access to Drupal logs, and help pages, can also be accessed from Drupal’s backend. It is useful for content editors and those managing the Drupal system.
The following figure demonstrates Drupal’s administrative backend, which can be found at /admin after logging in:
Figure 1.1 – Drupal’s administrative home page
At the top, Drupal has an administrative menu that helps navigate the entirety of Drupal’s administrative backend. This figure demonstrates the initial, primary administrative page that lists links within Drupal’s backend. Each category has a gray background that represents a core feature or subsystem. Under each category are links to pages that perform administrative actions or configure the behavior of that subsystem.
Since the backend configures Drupal and manages content, the frontend is responsible for serving content. Drupal’s render subsystem is used to correlate a page request to the corresponding response, which is dynamically returned by Drupal. While there is far more complexity, a high-level request flow interprets the path, gathers the relevant structured content from Drupal’s backend, maps the content to HTML templates found in the enabled Drupal theme, and returns rendered markup.
The following figure shows Drupal 10’s default home page rendered by the frontend presentation layer:
Figure 1.2 – Drupal’s default home page
While this shows simple, basic placeholder content, it differs drastically from Figure 1.1, given that it is presenting content and not configuring Drupal.
Consider authenticated users while using Drupal’s frontend and backend. Drupal can deliver content, but not just for anonymous visitors who visit a Drupal website. During frontend processing, Drupal can render content specific for the user who’s being authenticated. Such a capability allows you to leverage Drupal features to build dashboards with individualized content, create personalized experiences, and even deliver content moderation workflows that pair with Drupal’s frontend. The most common use case for authenticated users is still accessing and using the administrative backend of Drupal, but a user can be configured without permission to access the backend. Given users have an expanded role in Drupal, a user can log into Drupal with no backend access and get content that’s specific and relevant to them. Imagine building a social network where every user only sees content they subscribe to. Drupal can do that.
Drupal case studies start with their fundamental content management features, which build off of structured data. Drupal has been commonly used for blogs, websites, or news. Stanford University offers a web content management program that delivers Drupal and various content management features as a service through their IT department. The State of Georgia offers a similar web platform built with Drupal. Other popular Drupal websites include London.gov.uk, home.cern, unicef.org, the Syfy network, the State of Massachusetts, The Weather Channel, Tesla, Entertainment Weekly, NCAA, the Emmy Awards, and NASA.
Distributions in Drupal often represent popular use cases for Drupal, reducing the time and cost of creating multiple sites that have similar requirements. Websites built with the Open Social distribution (getopensocial.com) help create community-based websites with groups, events, private messaging, and enhanced user profiles. Case studies include Local Gov Drupal (drupal.org/project/localgov), The United Nations, The Salvation Army, and The European Commission. Drupal Commerce is a distribution tailored for eCommerce websites, with a series of optional features for payment gateway integrations, promotions/coupons, analytics, shipping, and fulfillment. Case studies include EuroCentres, Open Sesame, and Artellite.
Drupal has countless published case studies and even more undocumented installations that highlight its wide adoption. These case studies demonstrate Drupal’s ability to be used in different industries and verticals, as well as for different implementations.
This chapter covered introductory concepts regarding CMSs and highlighted how Drupal built a CMS through its high-level features. First, we introduced Drupal’s framework and extensibility value proposition, which enables both its vibrant community and enterprise-level customizations. Next, we reviewed Drupal.org, which introduced you to how to engage with the community, work with community projects, and the purpose of the Drupal Association. Finally, we looked at some case studies that demonstrate Drupal’s capabilities. The next chapter dives deeper into projects by reviewing core, contributed, and custom projects.
Drupal starts with a powerful, foundational core that all Drupal applications build from. This chapter describes what core is, how it was conceptually created, how to harness it to create a Drupal application, and how an application can be extended beyond just core. Learning how to create Drupal applications starts with enabling and configuring Drupal core features. It is only after leveraging core that the application should be extended through contributed and/or custom projects. This chapter serves as the foundation for configuring applications, understanding high-level architecture, and then solving additional problems through extended projects.
In this chapter, we’re going to cover the following main topics:
Drupal coreOverview of Drupal projectsDrupal modulesDrupal themesContributionDrupal core is the foundation of every Drupal application. It represents all out-of-the-box Drupal features and contains the framework every Drupal application is built on. It has the most rigorous contribution process while having the largest amount of contribution activity.
While Drupal itself, as an open source project, is free, it should be viewed more through the perspective of “free like a puppy.” Drupal code is freely available, and there is a vast community helping to maintain and support it. However, Drupal applications require ongoing maintenance. Major and minor upgrades need to be performed to update the code. The underlying servers and platform need to be maintained as core evolves its platform dependencies. The community helps promote efforts to more seamlessly and automatically perform code updates, but adopters are still largely responsible for running their own platforms or picking a commercial PaaS offering. This takes ongoing work and investment as it requires a conscious decision from those selecting Drupal as their digital experience framework. But Drupal and the framework that core provides can be extensible and address complex, enterprise digital needs that can deliver value in ways other platforms simply cannot. While it can complicate upgrades with the added complexity of custom code, these capabilities position Drupal as a powerful tool capable of addressing enterprise needs. Even with efforts that simplify the maintenance work required, adopters still need to understand Drupal and the systems required to run it. Small businesses that cannot make this investment may not be in a position to effectively get the same value out of Drupal as an enterprise would. Professionals should advocate for the right tool for the right job.
Every house has a foundation. Every car has a frame. And every Drupal application has a core. It is the basis of all Drupal applications.
Drupal core is an out-of-the-box Drupal application. When the core is first downloaded, the application loads Drupal’s core installer. After installation, the application renders Drupal’s content and affords access to Drupal’s core user login feature. Logged-in users can access Drupal’s administrative systems and content management tools. All of this is facilitated by Drupal’s core.
Drupal core is built to be modular. In this definition, there are a series of independent parts that encompass all of Drupal’s core. This modularity is incredibly useful to afford Drupal developers the ability to enable or disable parts independently based on their use case, and many of the parts of Drupal core are extensible through configuration and the framework. The core of Drupal and its modularity serve as an underlying design principle that has allowed Drupal to solve countless problems in the digital space and be able to deliver on a wide array of various use cases.
Drupal’s core also helps drive some governance aspects of Drupal. As an example, Drupal core sets the various system requirements needed for running the Drupal application. Drupal core has explicit open-source licensing that influences all other Drupal communities and projects. Developing core often sets the highest standard for contribution to a Drupal project through processes, tooling, quality standards, and more.
Drupal core also has a set of common features. The features deliver Drupal’s out-of-the-box value and help to differentiate Drupal from other digital content management applications.
Content management features help deliver on Drupal’s promise as a content management system (CMS). Such examples include the following:
Structured content: Nodes, content types, blocks, fields, field types (dates, phone numbers, links), and taxonomyContent features: WYSIWYG, comments, moderation/workflows, layout builder, API feeds/web services, multilingual, Drupal views, statistics/analytics, forums, books, and blocksDigital assets: Files (PDFs, Word documents), media (images and videos), and responsive image managementMigration: Methods to import and export content within DrupalEngagement: Contact forms and searchAdministrative features help provide the content management experience, manage Drupal features, or change Drupal’s settings. These include the following:
Authorization/authentication: User roles and permissionsConfiguration: Changing settings of the Drupal application, and managing the state of the application’s Drupal configurationLogging: Accessing and managing Drupal logsDocumentation: Help pages, inline help, and toursImportant note
It is always important to leverage Drupal core’s out-of-the-box features before performing custom development or installing other projects. Drupal core itself is feature-rich, and it is the most established aspect of Drupal. The core should be leveraged before extending it.
If some of the terminology or concepts are new to you, don’t fear this. These features are covered in depth in future chapters.
Drupal core is built on subsystems. Some subsystems can be considered features of Drupal, while others are low-level, fundamental capabilities that a feature can leverage. Some pragmatic examples of features include the “node” system, which is common for structured content, and the “media” system used for file asset management. Low-level subsystems include the module subsystem, which allows Drupal to be modular, and the database subsystem, which allows for persistent Drupal storage (not assets). The combination of these subsystems provides both the framework and the features offered by the core out of the box.
Some examples of these core systems include the following:
UserCronThemeCacheEntityBatchQueueDatabaseInstallerLocaleMailPluginTestDrupal is a PHP application that has harnessed modern PHP development practices. Drupal core is built on Symfony components that, in essence, offer low-level capabilities that Drupal adopted. Earlier versions of Drupal had their specific systems built into core that overlapped with widely adopted open-source capabilities offered throughout the PHP ecosystem. Drupal 8 introduced this change, which was a significant architectural shift from a more procedural legacy PHP application into more of an object-oriented (OO), modern PHP approach. Composer, a popular PHP-based command-line tool, is used to manage Drupal’s dependencies to pull projects and versions based on the core’s provided directives. Both the use of Symfony components and Composer represent common practices of modern PHP applications and allow Drupal to more effectively focus effort on its value proposition. It also allows Drupal community members to contribute to and influence the broader PHP ecosystem.
Drupal core leverages projects as the construct for its modularity. Projects are built with code and harness Drupal core’s framework to customize Drupal. Community members have contributed their projects on drupal.org. Projects created for the specific needs of a Drupal application are known as custom. Custom projects are intended to add specific business logic that may be unique to an organization, integrate internal enterprise systems, or add specific company branding.
Important note
Before creating custom projects, evaluate the contributed projects on drupal.org. Given the maturity of the Drupal project and the vast number of contributions, it is common to find a contributed project that can help address the desired use case. This all assumes the feature is not provided by the core itself.
Projects are managed by Drupal core for the application. Core can install, enable, and disable projects. Each version of the project is managed so that the core can check for updates. Core also has the concept of update hooks, which allow for new versions of a project to perform specific tasks once new code exists.
The first type of project is known asa module.
A module is a code that leverages Drupal’s framework for backend customization. This often modifies the Drupal application and is processed within the server. The core itself organizes its features by leveraging modules. This way, each application can control which core modules are installed based on the desired needs of the application.
Modules have compatibility with the core. Every major version of the core modifies its framework. Given the framework changes, modules must provide metadata that defines their compatibility with major core versions. It should not be assumed that every module found on drupal.org is compatible with the version of Drupal on the application. In fact, given that Drupal now has 10 major versions, basic searches for modules can find modules dating back to early versions of Drupal. Popular modules from earlier versions may have even been moved into core in later versions (for example, Views). The Content Construction Kit (CCK) module served as the basis for what later became Drupal’s Entity system.
Given the number of Drupal applications in the world, community members have created a large number of modules aimed at solving specific problems. It is best to check on drupal.org before investing time in coding something someone else contributed.
Some popular module examples include the following:
Webform: A robust and extensible form-building solutionRedirect: Creates manual and automatic path redirection, especially useful to have old content point to new contentPathauto: Provides automatic path generation forcontent managersGoogle Analytics: Enables integration with Google AnalyticsTaxonomy Menu: Allows for a hierarchical taxonomy to be rendered as a menuAntibot: Spam protection for form submissionsSitewide Alerts: A solution that posts a banner message at the top of every pageMetatag: Delivers more metadata for content toward