diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index b411b88..37b2dc4 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -51,6 +51,17 @@ public static function mainPropertyName() { */ public function __construct(DataDefinitionInterface $definition, $name = NULL, TypedDataInterface $parent = NULL) { parent::__construct($definition, $name, $parent); + // Data types such as Integer or String use a simple value property to + // manage their value, which is why TypedData::getValue() uses that property + // for convencience of those data types. By declaring it as a member + // variable of the TypedData class, however, PHP sets a NULL value to it + // upon instantiation. This breaks field types which have a 'value' property + // as by inheriting from this class they inherit from TypedData as well and, + // thus, $field_item->value returns NULL directly instead of asking + // FieldItemBase::__get() for the proper value stored in + // $field_item->values['value']. Hence, we unset the NULL value. + unset($this->value); + // Initialize computed properties by default, such that they get cloned // with the whole item. foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { diff --git a/core/lib/Drupal/Core/TypedData/TypedData.php b/core/lib/Drupal/Core/TypedData/TypedData.php index 3216d21..bd7caa7 100644 --- a/core/lib/Drupal/Core/TypedData/TypedData.php +++ b/core/lib/Drupal/Core/TypedData/TypedData.php @@ -44,6 +44,13 @@ protected $parent; /** + * The configuration value. + * + * @var mixed + */ + protected $value; + + /** * {@inheritdoc} */ public static function createInstance($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {