diff --git a/core/lib/Drupal/Core/Field/Plugin/DataType/Deriver/FieldItemDeriver.php b/core/lib/Drupal/Core/Field/Plugin/DataType/Deriver/FieldItemDeriver.php index 58fce03..c4cfeb1 100644 --- a/core/lib/Drupal/Core/Field/Plugin/DataType/Deriver/FieldItemDeriver.php +++ b/core/lib/Drupal/Core/Field/Plugin/DataType/Deriver/FieldItemDeriver.php @@ -79,7 +79,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->fieldTypePluginManager->getDefinitions() as $plugin_id => $definition) { $definition['definition_class'] = '\Drupal\Core\Field\TypedData\FieldItemDataDefinition'; $definition['list_definition_class'] = '\Drupal\Core\Field\BaseFieldDefinition'; - $definition['wrapped'] = FALSE; + $definition['unwrap_for_canonical_representation'] = FALSE; $this->derivatives[$plugin_id] = $definition; } return $this->derivatives; diff --git a/core/lib/Drupal/Core/Field/Plugin/DataType/FieldItem.php b/core/lib/Drupal/Core/Field/Plugin/DataType/FieldItem.php index 7327eb2..bcca2ec 100644 --- a/core/lib/Drupal/Core/Field/Plugin/DataType/FieldItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/DataType/FieldItem.php @@ -18,8 +18,7 @@ * id = "field_item", * label = @Translation("Field item"), * list_class = "\Drupal\Core\Field\FieldItemList", - * deriver = "Drupal\Core\Field\Plugin\DataType\Deriver\FieldItemDeriver", - * wrapped = false + * deriver = "Drupal\Core\Field\Plugin\DataType\Deriver\FieldItemDeriver" * ) */ abstract class FieldItem { diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index c5ac341..bbbc4d6 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -46,7 +46,7 @@ public function getContextValue() { } return NULL; } - return $this->typedDataManager->unwrap($this->contextData); + return $this->typedDataManager->getCanonicalRepresentation($this->contextData); } /** diff --git a/core/lib/Drupal/Core/TypedData/Annotation/DataType.php b/core/lib/Drupal/Core/TypedData/Annotation/DataType.php index 49d9fcd..3f277f2 100644 --- a/core/lib/Drupal/Core/TypedData/Annotation/DataType.php +++ b/core/lib/Drupal/Core/TypedData/Annotation/DataType.php @@ -107,18 +107,12 @@ class DataType extends Plugin { public $constraints; /** - * Whether data of this type is wrapped by typed data objects. - * - * Mostly, typed data objects wrap a data value to make it usable based - * on the Typed Data API. However, data which is already represented by PHP - * objects may opt to implement the Typed Data interface directly, such that - * a wrapping object becomes unnecessary. In that case, this variable should - * be set to FALSE. + * Whether the typed object wraps the canonical representation of the data. * * @var bool * - * @see \Drupal\Core\TypedData\TypedDataManager::unwrap() + * @see \Drupal\Core\TypedData\TypedDataManager::getCanonicalRepresentation() */ - public $wrapped = TRUE; + public $unwrap_for_canonical_representation = TRUE; } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index bbd05a9..ebdc1e5 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -416,31 +416,35 @@ public function clearCachedDefinitions() { } /** - * Unwraps a data object if needed. - * - * Unwraps the object unless the data object directly implements the Typed - * Data API. See \Drupal\Core\TypedData\Annotation\DataType::$wrapped. - * - * This may be used to ensure data is in the right representation before it is - * passed on to other code components. E.g., when typed data is validated it - * gets unwrapped before it is passed on to constraint validators, such that + * Gets the canonical representation of some data. + * + * The Typed Object often wraps the canonical representation of the + * data, while in other cases the Typed Object itself represents the main API + * and thus the canonical representation of the data. E.g., primitive values + * or entity objects are wrapped by Typed Objects, while field items and their + * lists use an object directly implemented the TypedDataInterface as + * canonical representation. + * + * The canonical representation is typically used when data is passed on to + * other code components. E.g. when Typed Data is validated the canonical + * representation is passed on to constraint validators, such that * entity objects get passed unwrapped and fields stay objects (which directly * implemented TypedDataInterface). * * @param \Drupal\Core\TypedData\TypedDataInterface $data - * The data object to unwrap. + * The data. * * @return mixed - * The data, without any wrapping Typed Data object. + * The canonical representation of the passed data. */ - public function unwrap(TypedDataInterface $data) { + public function getCanonicalRepresentation(TypedDataInterface $data) { $data_definition = $data->getDataDefinition(); // In case a list is passed, respect the 'wrapped' key of its data type. if ($data_definition instanceof ListDataDefinitionInterface) { $data_definition = $data_definition->getItemDefinition(); } $type_definition = $this->getDefinition($data_definition->getDataType()); - if (!empty($type_definition['wrapped'])) { + if (!empty($type_definition['unwrap_for_canonical_representation'])) { return $data->getValue(); } return $data; diff --git a/core/lib/Drupal/Core/TypedData/Validation/Metadata.php b/core/lib/Drupal/Core/TypedData/Validation/Metadata.php index 3f3ef11..6fe5255 100644 --- a/core/lib/Drupal/Core/TypedData/Validation/Metadata.php +++ b/core/lib/Drupal/Core/TypedData/Validation/Metadata.php @@ -73,7 +73,7 @@ public function accept(ValidationVisitorInterface $visitor, $typed_data, $group, // @todo: Do we have to care about groups? Symfony class metadata has // $propagatedGroup. - $visitor->visit($this, $this->typedDataManager->unwrap($typed_data), $group, $propertyPath); + $visitor->visit($this, $this->typedDataManager->getCanonicalRepresentation($typed_data), $group, $propertyPath); } /** @@ -100,7 +100,7 @@ public function getPropertyName() { * @return mixed The value of the property. */ public function getPropertyValue($container) { - return $this->typedDataManager->unwrap($this->typedData); + return $this->typedDataManager->getCanonicalRepresentation($this->typedData); } /** diff --git a/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php b/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php index 9aa57dc..80d3320 100644 --- a/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php +++ b/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php @@ -28,7 +28,7 @@ public function accept(ValidationVisitorInterface $visitor, $typed_data, $group, $data = NULL; } else { - $data = $this->typedDataManager->unwrap($typed_data); + $data = $this->typedDataManager->getCanonicalRepresentation($typed_data); } $visitor->visit($this, $data, $group, $propertyPath); $pathPrefix = isset($propertyPath) && $propertyPath !== '' ? $propertyPath . '.' : '';