Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Drupal 10 Development Cookbook

You're reading from   Drupal 10 Development Cookbook Practical recipes to harness the power of Drupal for building digital experiences and dynamic websites

Arrow left icon
Product type Paperback
Published in Feb 2023
Publisher Packt
ISBN-13 9781803234960
Length 442 pages
Edition 3rd Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Matt Glaman Matt Glaman
Author Profile Icon Matt Glaman
Matt Glaman
Kevin Quillen Kevin Quillen
Author Profile Icon Kevin Quillen
Kevin Quillen
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Chapter 1: Up and Running with Drupal 2. Chapter 2: Content Building Experience FREE CHAPTER 3. Chapter 3: Displaying Content through Views 4. Chapter 4: Extending Drupal with Custom Code 5. Chapter 5: Creating Custom Pages 6. Chapter 6: Accessing and Working with Entities 7. Chapter 7: Creating Forms with the Form API 8. Chapter 8: Plug and Play with Plugins 9. Chapter 9: Creating Custom Entity Types 10. Chapter 10: Theming and Frontend Development 11. Chapter 11: Multilingual and Internationalization 12. Chapter 12: Building APIs with Drupal 13. Chapter 13: Writing Automated Tests in Drupal 14. Chapter 14: Migrating External Data into Drupal 15. Index 16. Other Books You May Enjoy

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.

You have been reading a chapter from
Drupal 10 Development Cookbook - Third Edition
Published in: Feb 2023
Publisher: Packt
ISBN-13: 9781803234960
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.
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 $19.99/month. Cancel anytime