Preface

Drupal 9 is a powerful web-based content management system (CMS) that can be used to build anything from simple websites to powerful applications. While it is useful out of the box, it is designed with developers in mind.

The purpose of this book is to talk about the most common ways a Drupal website can be extended to provide new functionality. In doing so, the book will cover a number of extension points, but also illustrate many subsystems and APIs that can help you model, structure, and wire your business requirements.

Alongside the obligatory theoretical explanations, it will use a practical, example-based approach in order to break down complex topics and make them easier to understand. So, join me on this journey to discover exactly how powerful Drupal actually is.

Who this book is for

The primary target of this book is Drupal developers who want to learn how to write modules and develop in Drupal 9. It is also intended for Drupal site builders and PHP developers who have basic object-oriented programming skills.

What this book covers

Chapter 1, Developing for Drupal 9, provides an introduction to module development in Drupal. In doing so, it introduces the reader to the various subsystems and outlines the requirements for running a Drupal 9 application.

Chapter 2, Creating Your First Module, gets the ball rolling with the creation of the first Drupal module of the book. Its primary focus is to explore the most common things module developers need to know from the get-go.

Chapter 3, Logging and Mailing, is about the tools available for doing something every web-based application does and/or should be doing; that is, sending emails and logging events.

Chapter 4, Theming, presents the theme system from a module developer's perspective in Drupal 9.

Chapter 5, Menus and Menu Links, explores the world of menus in Drupal and shows how to programmatically create and work with menu links.

Chapter 6, Data Modeling and Storage, looks at the various types of storage available in Drupal, from the State system to configuration and entities.

Chapter 7, Your Own Custom Entity and Plugin Types, takes a hands-on approach in terms of creating a custom configuration and content entity type, as well as a custom plugin type for wiring up a practical functional example.

Chapter 8, The Database API, presents the database abstraction layer and discusses how we can work directly with data stored in custom tables.

Chapter 9, Custom Fields, exemplifies the creation of the three plugins necessary for creating a custom field that can be used on a Drupal content entity type.

Chapter 10, Access Control, explores the world of access restrictions in Drupal, from roles and permissions to route and entity access checks.

Chapter 11, Caching, looks at the various cache mechanisms available for module developers to improve the performance of their functionality.

Chapter 12, JavaScript and the AJAX API, introduces module developers to the specificities of writing JavaScript in Drupal, as well as the powerful AJAX system, which can be used to build advanced interactions.

Chapter 13, Internationalization and Languages, deals with the practices that Drupal module developers need to observe in order to ensure that the application can be properly translated.

Chapter 14, Batches, Queues, and Cron, explores the various ways module developers can structure their data-processing tasks in a reliable way.

Chapter 15, Views, looks at the various ways module developers can programmatically interact with Views and even expose their own data to them.

Chapter 16, Working with Files and Images, explores the various file and image APIs that allow module developers to store, track, and manage files in Drupal.

Chapter 17, Automated Testing, explores the various types of automated tests that developers can write for their Drupal applications so as to ensure stable and resilient code.

Chapter 18, Drupal 9 Security, explores the most common security principles that need to be observed when developing Drupal 9 modules.

To get the most out of this book

Readers don't need much to follow along with this book. A local environment setup capable of installing and running Drupal 9 (preferably with Composer) should suffice.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Drupal-9-Module-Development-Third-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "PHP executes Drupal's front controller file (index.php), which then creates a new Request object from the resource that was requested."

A block of code is set as follows:

name: Hello World

description: Hello World module

type: module

core_version_requirement: ^9

package: Custom

Any command-line input or output is written as follows:

../vendor/bin/phpunit tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php  

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Users can now reach this page from the module administration page by clicking on the Help link for each individual module that has this hook implemented"

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.102.112