diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index d045152..ad38b9d3 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -71,4 +71,34 @@ public function getLoadedRevisionId(); */ public function updateLoadedRevisionId(); + /** + * Flags the entity for deep serialization. + * + * When an entity is deeply serialized then its field items will have the + * opportunity to return also e.g. computed properties in order to serialize + * the whole entity structure and cover changes made on computed properties, + * which are not yet saved instead of only returning the metadata needed to + * re-compute/load the computed property. An example for this are entity + * reference fields, which during deep serialization will return their + * referenced entities. In this case not only the changes on the main entity + * will be serialized, but also the changes made on the referenced entities. + * + * Example usage: + * -Alter the title of a referenced entity and serialize the parent entity + * through deep serialization in order to serialize the change made on the + * referenced entity. + * @code + * $entity->entity_reference_field->entity->setTitle('new entity reference title'); + * $entity->setDeepSerialization(TRUE); + * serialize($entity); + * @endcode + * + * @param bool $deep_serialization + * TRUE if deep serialization should be performed when the entity is being + * serialized, FALSE otherwise. Defaults to TRUE. + * + * @return $this + */ + public function setDeepSerialization($deep_serialization); + } diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php index 0d6b210..d21a2a8 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php @@ -236,34 +236,4 @@ public function isValidationRequired(); */ public function setValidationRequired($required); - /** - * Flags the entity for deep serialization. - * - * When an entity is deeply serialized then its field items will have the - * opportunity to return also e.g. computed properties in order to serialize - * the whole entity structure and cover changes made on computed properties, - * which are not yet saved instead of only returning the metadata needed to - * re-compute/load the computed property. An example for this are entity - * reference fields, which during deep serialization will return their - * referenced entities. In this case not only the changes on the main entity - * will be serialized, but also the changes made on the referenced entities. - * - * Example usage: - * -Alter the title of a referenced entity and serialize the parent entity - * through deep serialization in order to serialize the change made on the - * referenced entity. - * @code - * $entity->entity_reference_field->entity->setTitle('new entity reference title'); - * $entity->setDeepSerialization(TRUE); - * serialize($entity); - * @endcode - * - * @param bool $deep_serialization - * TRUE if deep serialization should be performed when the entity is being - * serialized, FALSE otherwise. Defaults to TRUE. - * - * @return $this - */ - public function setDeepSerialization($deep_serialization); - } diff --git a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php index 6dc2ee6..f4fc99b 100644 --- a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php +++ b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Field; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; @@ -17,7 +18,7 @@ public function getSerializationValue($deep_serialization) { if ($deep_serialization) { $values = $this->getValue(TRUE); foreach ($values as $delta => $item_values) { - if (isset($values[$delta]['entity']) && ($values[$delta]['entity'] instanceof FieldableEntityInterface)) { + if (isset($values[$delta]['entity']) && ($values[$delta]['entity'] instanceof ContentEntityInterface)) { $values[$delta]['entity']->setDeepSerialization(TRUE); } }