Properly support string and text fields

Created on 9 May 2022, almost 3 years ago
Updated 4 April 2025, 5 days ago

Problem/Motivation

The TextFormatter used for string and text fields behaves differently than the core formatters for the same fields. For example for Text (formatted) fields, all the allowed HTML is escaped.

Steps to reproduce

  • Create a Text (formatted) field.
  • In Manage display, set the format as Heading.
  • Add formatted content to the field, for example: Example <em>emphasized</em> title.
  • See how the field value is displayed with the <em> tags escaped, due to Twig's autoescaping.

Proposed resolution

Use the same render arrays than core to display these fields, adding the heading tags as #prefix and #suffix.

It also has a slight performance benefit, because the Twig template is not used. I also included another minor performance tweak, which is setting the $size variable outside the foreach loop.

As a footnote, in my opinion this also has an extra benefit, and it's that you will be able to override the heading Twig template affecting only Heading fields, but not the core ones, which I think is preferrable.

Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

🇪🇸Spain gonssal

Live updates comments and jobs are added and updated live.
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.71.5 2024