Discovered in #58 of #3015438: Wrap entity objects in a ResourceObject which carries a ResourceType.
Postponed on #3024896: Remove Relationship and RelationshipItem classes because that issue will delete the offending code, making this outdated.
EntityReferenceFieldNormalizer has a pair of arrays which must be kept in sync when serializing entity reference items:
$entity_list[] = NULL;
$entity_list_metadata[] = [
However, in it, it also does this (pseudo-code):
$entity_list_metadata[] = $metadata;
// ...
if ($entity->isInternal()) {
continue;
}
$entity_list[] = $entity;
This means that if the entity is internal, the field's metadata is added to one array but the entity object is not added to the other. This will create a mismatch that will cause the JSON:API output for an entity reference field to be incorrect when an entity reference item that references an internal entity precedes one that does not.
Comments
Comment #2
wim leers🤦♂️
Great find.
Comment #3
wim leersComment #4
wim leers#3024896: Remove Relationship and RelationshipItem classes landed, so this is now no longer relevant! 🎉