This is related to how we validate the child entities inside the parent's entity constraint validator, we can use the following code to get the value of child entities.
$child_entities = $items->get('child_entity_field')->getValue();

When we adding new child entity, the new entity object can be accessed from $child_entities[0]['entity']. Below this is the structure of $child_entities when we print_r it.

Array
(
    [0] => Array
        (
            [weight] => 1
            [form] => 
            [needs_save] => 1
            [target_id] => 
            [entity] => ---> The entity object here.
        )
    [1] => Array
        (
            [weight] => 2
            [form] => 
            [needs_save] => 1
            [target_id] => 
            [entity] => ---> The entity object here.
        )
)

But, when we update the existing child entity, the entity object is not included anymore. When we print_r it, we get the following structure.

Array
(
    [0] => Array
        (
            [weight] => 0
            [form] => 
            [needs_save] => 
            [target_id] => 8
        )

    [1] => Array
        (
            [weight] => 1
            [form] => 
            [needs_save] => 
            [target_id] => 9
        )
)

What about including the updated child entity structure there just like when we add the new one? I think it will be usefull because we can use that in constraint validator in the parent entity.

Comments

bogeyman created an issue. See original summary.

bogeyman’s picture

Issue summary: View changes
bogeyman’s picture

Issue summary: View changes
dieterholvoet’s picture

Status: Active » Postponed (maintainer needs more info)

I was experiencing a similar issue: I was trying to get the referenced entities in a constraint validator in the parent entity as well, but I was trying to get them using $child_entities = $items->get('child_entity_field')->referencedEntities();. That should have worked but didn't, and after a lot of digging I found out why: #2826717: EntityReferenceFieldItemList::referencedEntities might not return up-to-date entity objects.

So in short: please try to include a patch from the MR in #2826717: EntityReferenceFieldItemList::referencedEntities might not return up-to-date entity objects in your project and try to load the entities using referencedEntities(), that should give you the result you need. Let me know if that doesn't fix your issue.