Note: Issue and code generated with the help of a coding agent. All reviewed and checked carefully!

Problem/Motivation

There is currently no clean way to output an entity reference field's label as a plain prop. The field:entity_reference_label core-formatter wrapper renders through the Drupal render pipeline (#plain_text), so the attribute value arrives HTML-escaped (Word & Word2). Frontend frameworks (Vue, React, …) escape on output as well → the user sees a double-escaped label (&) for any label containing &, <, > or ". The existing entity_ce_render formatter can't help either: it always emits a nested element/object, never a bare string prop.

CE output is data, not markup: values should be raw and escaped exactly once, by the consumer.

Proposed resolution

Add two formatters for entity_reference / entity_reference_revisions:

  • entity_label — the referenced entity's label as a raw scalar attribute (array for multi-value). Covers the very common "reference → plain label prop" case.
  • entity_reference — basic reference info: id, url (+ optional label), with flatten and absolute-URL options.

Add a base class mirroring core's EntityReferenceFormatterBase: bulk-loading via prepareBuild(), in-context translation, view-access check, cache metadata.

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

fago created an issue. See original summary.

fago’s picture

Status: Active » Needs work
fago’s picture

Status: Needs work » Needs review

  • fago committed 50d801dc on 3.x
    feat: #3616027 Add dedicated entity_label and entity_reference CE field...
fago’s picture

Status: Needs review » Fixed

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.

fago’s picture

Title: Add entity_label and entity_reference CE field formatters for raw reference outpu » Add entity_label and entity_reference CE field formatters for raw reference output

  • fago committed 50d801dc on 3472359-custom-elements-3472359-multiple
    feat: #3616027 Add dedicated entity_label and entity_reference CE field...

Status: Fixed » Closed (fixed)

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