Problem/Motivation

When comparing revisions of an entity that contains an Entity Reference field, the Diff module may fail to display reference updates.
This occurs when the field value provides only the target_id (e.g., after an entity reference update) but does not include the loaded entity object.

As a result, the updated reference change is not visible in the Diff output, which can cause confusion for users reviewing content revisions.

Steps to reproduce

Create a content type with an Entity Reference field referencing another entity (e.g., Node or Taxonomy Term).

Create a node and set a reference value.

Edit the node and change the reference to a different entity.

Go to Revisions → Compare revisions (Diff view).

Observe that the entity reference field does not display any change, even though the reference has been updated.

Proposed resolution

Add a fallback condition in EntityReferenceFieldBuilder to handle cases where 'target_id' exists but 'entity' is not available.

This ensures the updated entity reference ID is displayed properly in the Diff output.

Remaining tasks

Add fallback for target_id when entity is missing

Verify that updated entity references appear in revision comparison

Confirm backward compatibility with existing Diff displays

User interface changes

In Diff view, when only the target_id is available, the output will now display a message such as:
Entity ID: 25

API changes

None

Data model changes

None

Issue fork diff-3552007

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

shaila.amale created an issue. See original summary.

shaila.amale’s picture

acbramley’s picture

Version: 8.x-1.9 » 2.x-dev
Status: Needs review » Needs work

benstallings made their first commit to this issue’s fork.

benstallings’s picture

Status: Needs work » Needs review
acbramley’s picture

Status: Needs review » Needs work

phpstan is failing.

benstallings’s picture

Status: Needs work » Needs review

@acbramley those are all deprecations that don't take effect until Drupal 13, and they are unrelated to this MR. Phpstan for the current version is all green. If I've missed something, please let me know specifically what you're referring to.

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

@benstallings woops, I thought we were ignoring failures on next major but I had the config flipped.

acbramley’s picture

Status: Reviewed & tested by the community » 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.

Status: Fixed » Closed (fixed)

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