diff --git a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php index 2756730799..0bf5e152eb 100644 --- a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php +++ b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Entity\Plugin\DataType\EntityReference; use Drupal\Core\Form\FormStateInterface; /** @@ -16,13 +17,20 @@ class EntityReferenceFieldItemList extends FieldItemList implements EntityRefere */ public function getSerializationValue($deep_serialization) { // When performing a deep serialization then we overwrite the parent method - // in order to include the computed properties i.e. in the current case the - // referenced entity objects and flag them for deep serialization as well. + // in order to include the properties holding entities and flag the entities + // for deep serialization as well. if ($deep_serialization) { $values = $this->getValue(TRUE); foreach ($values as $delta => $item_values) { - if (isset($values[$delta]['entity']) && ($values[$delta]['entity'] instanceof ContentEntityInterface)) { - $values[$delta]['entity']->setDeepSerialization(TRUE); + /** @var \Drupal\Core\Field\FieldItemInterface $item */ + $item = $this->get($delta); + foreach ($item_values as $property_name => $property_value) { + $property = $item->get($property_name); + if ($property instanceof EntityReference) { + if (isset($values[$delta][$property_name]) && ($values[$delta][$property_name] instanceof ContentEntityInterface)) { + $values[$delta][$property_name]->setDeepSerialization(TRUE); + } + } } } }