diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index ad38b9d3..97880fc 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -84,7 +84,7 @@ public function updateLoadedRevisionId(); * 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 + * - 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 diff --git a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php index f4fc99b..372cf2f 100644 --- a/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php +++ b/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php @@ -15,17 +15,14 @@ class EntityReferenceFieldItemList extends FieldItemList implements EntityRefere * {@inheritdoc} */ public function getSerializationValue($deep_serialization) { + $values = parent::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 ContentEntityInterface)) { $values[$delta]['entity']->setDeepSerialization(TRUE); } } } - else { - $values = parent::getSerializationValue($deep_serialization); - } return $values; } diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index 139463e..87fdb8c 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -104,8 +104,8 @@ protected function getSetting($setting_name) { public function getValue($include_computed = FALSE) { $value = parent::getValue(); - // Include computed properties if the condition of - // ::includeComputedProperties() is fulfilled. + // Allow field types to opt-in or opt-out of including computed properties + // in certain cases. if ($this->includeComputedProperties($include_computed)) { // Iterate only over computed properties and include them, as the parent // method is not including them. @@ -122,7 +122,7 @@ public function getValue($include_computed = FALSE) { /** * Checks if included properties have to be included. * - * Helper method for ::getValue() to check if included properties have to be + * Helper method for ::getValue() to check if included properties should be * included. * * @param bool $include_computed @@ -130,8 +130,12 @@ public function getValue($include_computed = FALSE) { * * @return bool * TRUE if computed properties have to be included. FALSE otherwise. + * + * @see ::getValue() */ protected function includeComputedProperties($include_computed) { + // Even if computed fields were requested, do not attempt to compute + // anything if there are no actual values. return $include_computed && !$this->isEmpty(); } diff --git a/core/lib/Drupal/Core/Field/FieldItemListInterface.php b/core/lib/Drupal/Core/Field/FieldItemListInterface.php index fd5cd68..898356f 100644 --- a/core/lib/Drupal/Core/Field/FieldItemListInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemListInterface.php @@ -275,13 +275,14 @@ public function equals(FieldItemListInterface $list_to_compare); * Gets the data value prepared for serialization. * * @param bool $deep_serialization - * Whether a deep serialization is running. - * - * @return mixed - * Depending on whether deep serialization is running or not the returned - * value might be either the data value as returned by ::getValue() if deep - * serialization is not running or additionally contain computed properties - * next to the data values if deep serialization is running. + * Whether a deep serialization should be performed. + * + * @return array[] + * Depending on whether deep serialization is being performed or not the + * returned value might be either the data value as returned by ::getValue() + * if deep serialization is not being performed or additionally contain + * computed properties next to the data values if deep serialization is + * being performed. */ public function getSerializationValue($deep_serialization);