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.
Issue fork custom_elements-3616027
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
Comment #3
fagoComment #4
fagoComment #6
fagoComment #8
fago