Motivation

Current default output for an entity reference field, like article tags, is that:

 <div slot="tags">
        <field-entity-reference target-id="1" slot="default"></field-entity-reference>
 </div>

Proposed resolution

Improve to something like

		<field-entity-reference slot="tags" href="/the/canonical/link" label="the-entity-label"></field-entity-reference>
		<field-entity-reference slot="tags" href="/the/canonical/link2" label="the-entity-label2"></field-entity-reference>
 

This will imply a BC change for everyone relying on the default custom element processor.

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

Issue summary: View changes

fago’s picture

Status: Active » Needs review
fago’s picture

I improved the code bit more, now it outputs entity references by default using a simple link in the entity slot:

Example output

<field-entity-reference target-id="2" slot="tags">
<a href="/taxonomy/term/2" type="taxonomy_term" slot="entity">test</a>
</field-entity-reference>

I think this is fine as default, everything more will need dedicated processors with suiting output anyway.

fago’s picture

and further improved defaults if entities are not accessible, so the link is not output. This should also fix tests.

fago’s picture

Status: Needs review » Fixed

should be all good now, thus merged.

  • fago committed 0c8bbfc on 8.x-2.x
    Issue #3190604 by fago: Remove deprecated code when generationg defaults...
  • fago committed 6acbee3 on 8.x-2.x
    Issue #3190604 by fago: Fix default handling of entity references.
    
  • fago committed a3bf64d on 8.x-2.x
    Issue #3190604 by fago: Keep entity references without accessible entity...

Status: Fixed » Closed (fixed)

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