Problem/Motivation

When using custom elements with string or string_long fields, there is no suitable CE field formatter that outputs the raw text value. The auto formatter works but doesn't trim whitespace or strip newlines.

Proposed resolution

Add a new plain_text CE field formatter that:

  • Only applies to string and string_long field types
  • Outputs the raw field value directly as a CE attribute (no render pipeline)
  • Trims leading/trailing whitespace
  • Optionally strips newlines and collapses multiple spaces into one
  • Optionally truncates via Unicode::truncate() with word-safe and ellipsis options

The formatter bypasses Drupal's rendering system entirely, setting the value directly on the custom element. This avoids any HTML escaping or markup wrapping that is inappropriate for JSON API output.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

arthur_lorenz created an issue. See original summary.

arthur_lorenz’s picture

Status: Active » Needs review
fago’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thx. I reviewed it and added a few remarks. Also, this is missing tests, each formatter must come with its own test-case. see others.

arthur_lorenz’s picture

Status: Needs work » Needs review

Thx, updated the formatter and added kernel tests.

  • fago committed 44309507 on 3.x authored by arthur_lorenz
    feat: #3581394 Add plain_text CE field formatter for string fields
    
    By:...
fago’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

thank you, all good new + manual testing was also good! Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.