Provide a method for accessing referenced entity from EntityReferenceItem or EntityReferenceItemBase

Created on 29 February 2024, 4 months ago

Problem/Motivation

When interacting with a Reference field there is no explicit way to get the related entity. For example a referenced node or taxonomy term.

Additionally, at least in phpstorm, the magic getter method retrieving a referenced entity looks to the IDE like its connected to the parent entity property on DataType\EntityAdapter

Steps to reproduce

This is simplified but in some code interacting with a taxonomy term do something like this.

$tag = $node->get('field_tags')->first();
if ($tag) {
  // This entity gives you the referenced entity but triggers and IDE warning and is unclear what you're interacting with.
  $term = $tag->entity;
}

Proposed resolution

Provide a method named something like getReferencedEntity on EntityReferenceItem or EntityReferenceItemBase to improve the usability of interacting with the referenced entities and entity reference fields.

see πŸ› ResourceTypeRepository wrongly assumes that all entity reference fields have the setting "target_type" Fixed for a similar discussion on this.

Remaining tasks

User interface changes

API changes

This will likely require a new interface or changes to the existing interface.

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated about 15 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @neclimdul
  • πŸ‡ΊπŸ‡ΈUnited States dww

    I was in the Slack thread (attached with permission) where this was discussed. We're all in favor. Thanks for opening the issue!

Production build 0.69.0 2024