Problem
When using the "Custom element: Rendered entity" (entity_ce_render) formatter with the explicit JSON format, entity reference fields that are output as
props (not slots) also use explicit format with element/props separation. This doesn't make sense when rendered as prop, you want the data and are not interested in the prop/slot separation. (This worked nice in implicit format.)
Current output:
{ "element": "marketing-features", "props": { "features": [ { "element": "feature-item", "props": { "title": "Feature One", "icon": "..." } } ] } }
Expected output:
{ "element": "marketing-features", "props": { "features": [ { "element": "feature-item", "title": "Feature One", "icon": "..." } ] } }
Additionally we might want to consider ommitting the element attribute when rendering as prop..
Steps to reproduce
- Configure
custom_elements.settings.json_formattoexplicit - Create an entity with an entity reference field using
entity_ce_renderformatter configured as a prop (not slot) - View the JSON output - nested elements use explicit format with
propswrapper
Proposed resolution
- In
EntityReferenceCeFieldFormatter::build(), pass'explicit' => FALSEin the normalizer context when outputting entity references as
props (attributes), so nested elements use implicit/flat format. - Add a formatter setting "Hide element key" (default: TRUE for single-value refs) to omit the
elementkey from the output when it's redundant.
Remaining tasks
- Implement the fix
- Add/update tests
User interface changes
New checkbox in entity_ce_render formatter settings: "Hide element key" (or make it default behavior for single-value fields).
API changes
For explicit output format the ce-enttiy-reference output changes *when* configured as prop. But that's what the issue is about.
Issue fork custom_elements-3571516
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
fagoadded MR, testing.
Comment #5
fagoWorks great, comes with tests, all good - merged.