Book Image

Drupal 10 Development Cookbook - Third Edition

By : Matt Glaman, Kevin Quillen
Book Image

Drupal 10 Development Cookbook - Third Edition

By: Matt Glaman, Kevin Quillen

Overview of this book

This new and improved third edition cookbook is packed with the latest Drupal 10 features such as a new, flexible default frontend theme - Olivero, and improved administrative experience with a new theme - Claro. This comprehensive recipe book provides updated content on the WYSIWYG (What You See Is What You Get) editing experience, improved core code performance, and code cleanup. Drupal 10 Development Cookbook begins by helping you create and manage a Drupal site. Next, you’ll get acquainted with configuring the content structure and editing content. You’ll also get to grips with all new updates of this edition, such as creating custom pages, accessing and working with entities, running and writing tests with Drupal, migrating external data into Drupal, and turning Drupal into an API platform. As you advance, you’ll learn how to customize Drupal’s features with out-of-the-box modules, contribute extensions, and write custom code to extend Drupal. By the end of this book, you’ll be able to create and manage Drupal sites, customize them to your requirements, and build custom code to deliver your projects.
Table of Contents (17 chapters)

Customizing the display output of content

Drupal provides display view modes that allow you to customize the fields and other properties attached to an entity. In this recipe, we will adjust the teaser display mode of an Article content type. Each field or property has controls for displaying the label, the format to display the information in, and additional settings for the format.

Harnessing view displays allows you to have full control over how content is viewed on your Drupal site.

How to do it…

  1. Now, it is time to customize the form display mode by navigating to Structure and then Content Types.
  2. We will modify the Article content type’s display. Click on the drop button arrow and select Manage display.
  3. Click on the Teaser view mode option to modify it. Teaser view mode is used in node listings, such as the default home page.
  4. Drag the Tags field to the hidden section. The tags on an article will no longer be displayed when viewing a Teaser view mode.
  5. Click on the settings cog icon for the Body field to adjust the trimmed limit. The trim limit is a fallback for the summary or trimmed format when the summary of a text-area field is not provided. Modify this by changing it from 600 to 300.
  6. Click on Save to save all the changes that you have made.
  7. View the home page and review the changes that have taken effect.

How it works…

The default rendering system for an entity uses view displays. View display modes are configuration entities. Since view display modes are configuration entities, they can be exported using configuration management.

When a content entity is rendered, the view display goes through each field formatter configured in the display. The field formatter is the option chosen from the Format property of the Manage Display form and identifies what code should be used to render the field value. The field value is retrieved from the entity and passed to the field formatter plugin that has been instantiated with the configuration provided to the view display. This collection of render data is then passed through the rest of Drupal’s render pipeline.

There’s more…

We will discuss more items for managing the form of a content entity in the following section.

Managing view display modes

Additional form display modes can be added by visiting Structure and then Display Modes under View Modes. Each content entity type has a hidden default view mode that always exists. Additional view display modes can be added and configured using the display management form.

These view modes can then be leveraged when displaying content with views, the Rendered entity field formatter for entity references, or when rendering entities with custom code.