Reader small image

You're reading from  Modernizing Drupal 10 Theme Development

Product typeBook
Published inAug 2023
PublisherPackt
ISBN-139781803238098
Edition1st Edition
Concepts
Right arrow
Author (1)
Luca Lusso
Luca Lusso
author image
Luca Lusso

Luca Lusso is a Drupal developer with more than 15 years experience, he started with Drupal 5 and PHP 5 in an era where deployments with FTP were still a thing. Since then, he worked as a consultant and contributed to build some of the biggest Drupal websites in Italy. Luca is also a teacher and he has taught Drupal to a lot of different teams, from universities to big system integrators. Luca is an open source lover and Drupal contributor, he maintains some popular modules like WebProfiler and Monolog. He's also a speaker in conferences like DrupalCon Europe and Drupal Developer Days. Lately, he has shifted his interest towards frontend performances. Luca holds a master's degree in Computer Science and he's an Acquia certified developer.
Read more about Luca Lusso

Right arrow

Preface

Working with themes in Drupal is not an easy task, and it is typical to get lost digging through all the layers and APIs involved. Modernizing Drupal 10 Theme Development deep-dives into the theme layer of the new Drupal 10.

In this book, we’ll explore how the Content Management System builds its pages, starting with all the basic concepts you need to develop a new Drupal theme from scratch and progressing to new features, such as starter kits, Single Directory Components, and decoupled architectures.

We want you to concentrate on the book’s main topic, so we’ve provided a design system, the Drupal configuration, and an opinionated stack to run a website on your local machine.

Chapter after chapter, Modernizing Drupal 10 Theme Development will guide you from a set of unstyled pages to a production-ready website that is fast and accessible.

Of course, we’ll take a modern approach, using cutting-edge technologies, such as Storybook, theme starter kits, SDCs, and decoupled architectures.

I like to delve about a topic only after all the concepts it builds on are evident; for this reason, the order of some chapters may seem unusual. Trust me – this is better than going back and forth trying to remember in a later chapter what we discussed at the beginning of the book.

Who this book is for

This book has been designed with two kinds of developers in mind. The first are frontend designers, whose job is to take a configured Drupal site and provide a style, following some design guidelines. We expect those users to know HTML and CSS and be willing to get their hands dirty with some PHP code.

The second group consists of backend developers. Drupal provides many premade features and technologies that streamline the process of creating exceptional frontends. However, I often observe instances where developers redo things that Drupal already provides. With this book, my intention is for backend developers to embrace Drupal’s best practices as much as possible.

What this book covers

Chapter 1, Setting Up a Local Environment, guides you to set up an opinionated local environment to work with Drupal. You’ll learn how to install and configure some tools such as Docker, DDEV, and Visual Studio Code. We’ll then clone a Git repository, install Drupal, and set up the system to start working on the frontend.

Chapter 2, Creating a New Theme and Setting Up a Build Process, starts by discussing building a new theme instead of using a ready-to-use one. You’ll learn what a starter kit is and how to use it to generate a new theme. Finally, we set up some processes to enforce coding standards, both locally and in a continuous integration pipeline.

Chapter 3, How Drupal Renders an HTML Page, talks about the rendering pipeline of Drupal. You’ll learn everything you need to know about how Drupal turns its internal data structures into HTML pages, with CSS and JavaScript attached.

Chapter 4, Mapping the Design to Drupal Components, explains how to develop the design system. We’ll step away from Drupal briefly to talk about how to split pages into components and how to use tools such as Storybook to work on templates, before setting up a Drupal instance. Subsequently, we will map each component to a data structure in Drupal.

Chapter 5, Styling the Header and Footer, examines the layout that stays the same on every page. In this chapter, you’ll learn about regions and blocks, how to override a core template to provide your own, and how to style a Drupal menu.

Chapter 6, Styling the Content, digs into the main part of a Drupal page, the content. We’ll talk about entities and fields, media, and taxonomies. You’ll learn some different ways to structure content in Drupal and how to customize the WYSIWYG editor.

Chapter 7, Styling Forms, explores how forms work on a Drupal site. You’ll learn how a form is structured, which templates it uses, and how to override and style them. We’ll then use the acquired knowledge to style the user login form.

Chapter 8, Styling Views, discusses one of the most complex topics in Drupal core. The Views module is as powerful as it is difficult to understand and style. We’ll talk about Views templates, exposed filters, and pagers.

Chapter 9, Styling Blocks, details how to style the parts of a page that aren’t the main content. You’ll learn the differences between editorial and programmatic blocks and how to style titles and breadcrumbs.

Chapter 10, Styling Maintenance, Taxonomy, Search Results, and 403/404 Pages, discusses a set of pages that sometimes are overlooked but that provide a great level of professionalism if styled correctly.

Chapter 11, Single Directory Components, digs into one of the new features of Drupal. We’ll discuss how Drupal core implements the concept of components and how to leverage it to rebuild some of our templates using the new approach. You’ll learn how to use and override components and expose them to Storybook.

Chapter 12, Creating Custom Twig Functions and Filters, explains how to extend Twig. You’ll learn how to define a new function and a new filter for Twig and why this is the best way to move the business logic away from the theme layer.

Chapter 13, Making a Theme Configurable, explores how Drupal allows you to reuse the same theme on different websites by making it configurable. We’ll also talk about sub-theming and how and when it’s helpful to define a sub-theme.

Chapter 14, Improving Performance and Accessibility, discusses optimizations. You’ll learn how to improve the performance of your website and how to make it as accessible as possible, as your users deserve.

Chapter 15, Building a Decoupled Frontend, scratches the surface of one of the most hyped topics in recent years. We’ll talk about how to leverage Drupal APIs to expose content and configuration to third-party systems and how to write some simple JavaScript clients to consume that data. You’ll learn how to install and configure a Next.js instance to build a fully decoupled site.

To get the most out of this book

This book assumes you know HTML and CSS and some JavaScript. It also assumes that you can use basic shell commands, can install software from web downloads onto your computer, and have basic familiarity with an integrated development environment. Basic knowledge of PHP will also be helpful.

Software covered in the book

OS requirements

Docker

Windows, macOS, or Linux

DDEV

Windows, macOS, or Linux

GIT

Windows, macOS, or Linux

Visual Studio Code

Windows, macOS, or Linux

Drupal 10

Windows, macOS, or Linux

Next.js

Windows, macOS, or Linux

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is 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 GitHub at https://github.com/PacktPublishing/Modernizing-Drupal-10-Theme-Development. If there’s an update to the code, it will be updated in the 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: “Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system.”

A block of code is set as follows:

<div class="relative">
  <a href="{{ link }}" title="{{ title }}">
    <div
      class="z-10 h-48 w-full border-2 border-nord-4 bg-
        cover bg-center bg-no-repeat opacity-50"
      style="background-image:url('{{ image }}');"
    ></div>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<div class="relative">
  <a href="{{ link }}" title="{{ title }}">
    <div
      class="z-10 h-48 w-full border-2 border-nord-4 bg-
        cover bg-center bg-no-repeat opacity-50"
      style="background-image:url('{{ image }}');"
    ></div>

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

^ array:4 [
  "uri" => "entity:node/8"
  "title" => "Let's do some ice climbing"
  "options" => []
  "_attributes" => []
]

Bold: Indicates a new term, an important word, or words that you see on screen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Click on the Preferences link to open the Preferences window.

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, email us at customercare@packtpub.com and mention the book title in the subject of your message.

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 and fill in the form.

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 copyright@packt.com 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.

Share Your Thoughts

Once you’ve read Modernizing Drupal 10 Theme Development, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781803238098

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Modernizing Drupal 10 Theme Development
Published in: Aug 2023Publisher: PacktISBN-13: 9781803238098
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Luca Lusso

Luca Lusso is a Drupal developer with more than 15 years experience, he started with Drupal 5 and PHP 5 in an era where deployments with FTP were still a thing. Since then, he worked as a consultant and contributed to build some of the biggest Drupal websites in Italy. Luca is also a teacher and he has taught Drupal to a lot of different teams, from universities to big system integrators. Luca is an open source lover and Drupal contributor, he maintains some popular modules like WebProfiler and Monolog. He's also a speaker in conferences like DrupalCon Europe and Drupal Developer Days. Lately, he has shifted his interest towards frontend performances. Luca holds a master's degree in Computer Science and he's an Acquia certified developer.
Read more about Luca Lusso