Add formatters and other mechanisms as alternative to base fields directly in entity templates

Created on 15 February 2019, over 5 years ago
Updated 16 June 2023, about 1 year ago

Problem/Motivation

As explained in the parent META issue ✨ [META] Expose Title and other base fields in Manage Display Active , the node template directly includes markup for the title and submitted information. This is not compatible with enabling these base fields to be configurable via the field UI. The same is true for various other entity type base fields.

As part of the solution for fixing that, we need a mechanism to reproduce a comparable and equivalent appearance. Plus we need this mechanism to be very easy to enable/configure without adding any extra dependencies. There are two cases that together can solve all core entity types looking pretty close to how they do already (excluding the aggregator module due to #3267458: Deprecate aggregator module in Drupal 9.4 β†’ ).

  1. Title: with configurable tag and option to link to the entity. Used on many entities.
  2. "Submitted": based on the "Author" formatter with additions. There is an optional user picture, and a wrapping sentence "Submitted by UUU on DDD", which includes the creation date. Used on node, comment, and could also apply to media.

Proposed resolution

There are many possible ways to solve this (see below under remaining tasks for other possibilities). For this issue, we need something simple, generating close to equivalent markup, and without forcing extra dependencies (such as Layout Builder). This unblocks the path forward for #3036862: Expose Title and other base fields in Manage Display in Drupal Core β†’ and #3176673: Deprecate non-standard display of title and other base fields β†’ - we can only deprecate the old way once we have created a new equivalent.

Custom formatters seem like the right answer.

  • They can be enabled/configured quickly in the UI.
  • It's possible to use them as the default in baseFieldDefinitions(), entity_form_display.*.yml, or custom hooks.
  • If a site doesn't want to use them, they don't get in the way.
  • They support powerful customisation with templates and hooks.
  • The code is simple and already written/tested in the contributed module Manage Display β†’ .

Copy the Title and Submitted formatters into core. Not much needs changing except to add tests.

Remaining tasks

We can cover some more advanced and sophisticated options for "Submitted" in follow-on issues. People can add many other possibilities in contrib modules. The [italic bracketed text] explains why each one wasn't chosen for this issue.

  1. Create a custom Layout Builder block. [Forces use of Layout Builder]
  2. Use hook_entity_extra_field_info(). [See below]
  3. Create a general mechanism for combining fields?? [Longer-term initiative that will take time]

The extra field option could work, but when examined in detail, it seems less suitable for "Submitted". It could be a good option in a Contrib module.

  • Extra fields don't currently allow settings (in particular to configure the user picture).
  • The extra field would combine/wrap the output of the underlying fields (uid and created). It works best if they don't have configurable display - which would not be acceptable for Core. (Reasons are: the extra field relies on the underlying fields having specific display settings; having the extra field and the separate fields in Manage Display is confusing.)
✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom AdamPS

Live updates comments and jobs are added and updated live.
  • Field UX

    Usability improvements related to the Field UI

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024