diff --git a/core/lib/Drupal/Core/Config/Schema/Mapping.php b/core/lib/Drupal/Core/Config/Schema/Mapping.php index b7bddb3..752ad46 100644 --- a/core/lib/Drupal/Core/Config/Schema/Mapping.php +++ b/core/lib/Drupal/Core/Config/Schema/Mapping.php @@ -53,10 +53,6 @@ public function get($property_name) { * Implements Drupal\Core\TypedData\ComplexDataInterface::set(). */ public function set($property_name, $value, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } // Set the data into the configuration array but behave according to the // interface specification when we've got a null value. if (isset($value)) { @@ -71,6 +67,10 @@ public function set($property_name, $value, $notify = TRUE) { $property->setValue($value); return $property; } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 2c3feef..59dfc6d 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -49,10 +49,6 @@ public function setValue($values, $notify = TRUE) { $keys = array_keys($this->getPropertyDefinitions()); $values = array($keys[0] => $values); } - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } $this->values = $values; // Update any existing property objects. foreach ($this->properties as $name => $property) { @@ -63,6 +59,10 @@ public function setValue($values, $notify = TRUE) { $property->setValue($value, FALSE); unset($this->values[$name]); } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** @@ -83,10 +83,6 @@ public function __get($name) { * Overrides \Drupal\Core\TypedData\Type\Map::set(). */ public function set($property_name, $value, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } // For defined properties there is either a property object or a plain // value that needs to be updated. if (isset($this->properties[$property_name])) { @@ -96,6 +92,10 @@ public function set($property_name, $value, $notify = TRUE) { else { $this->values[$property_name] = $value; } + // Directly notify ourselves. + if ($notify) { + $this->onChange($property_name); + } } /** @@ -134,6 +134,8 @@ public function onChange($property_name) { } // Remove the plain value, such that any further __get() calls go via the // updated property object. - unset($this->values[$property_name]); + if (isset($this->properties[$property_name])) { + unset($this->values[$property_name]); + } } } \ No newline at end of file diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Entity.php b/core/lib/Drupal/Core/Entity/Field/Type/Entity.php index 7eda574..400c484 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Entity.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Entity.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\AbstractEntity. + * Contains \Drupal\Core\Entity\Field\Type\Entity. */ namespace Drupal\Core\Entity\Field\Type; diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityReference.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityReference.php index 068fdd9..d24d76d 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityReference.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityReference.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Entity\Field\Type\EntityWrapper. + * Contains \Drupal\Core\Entity\Field\Type\EntityReference. */ namespace Drupal\Core\Entity\Field\Type; @@ -12,24 +12,31 @@ use InvalidArgumentException; /** - * Defines an 'entity_reference' data type, e.g. the computed 'entity' property of entity references. + * Defines an 'entity_reference' data type. + * + * This serves as 'entity' property of entity reference field items and gets + * its value set from the parent, i.e. LanguageItem. * * The plain value of this reference is the entity object, i.e. an instance of - * Drupal\Core\Entity\EntityInterface. For setting the value the entity object + * \Drupal\Core\Entity\EntityInterface. For setting the value the entity object * or the entity ID may be passed, whereas passing the ID is only supported if * an 'entity type' constraint is specified. * * Some supported constraints (below the definition's 'constraints' key) are: * - EntityType: The entity type. Required. * - Bundle: (optional) The bundle or an array of possible bundles. - * - * Required settings (below the definition's 'settings' key) are: - * - source: The ID property used for loading the entity object. */ class EntityReference extends DataReferenceBase { /** - * Implements \Drupal\Core\TypedData\DataReferenceInterface::getTargetDefinition(). + * The entity ID. + * + * @var integer|string + */ + protected $id; + + /** + * {@inheritdoc} */ public function getTargetDefinition() { $definition = array( @@ -45,64 +52,75 @@ public function getTargetDefinition() { } /** - * Implements \Drupal\Core\TypedData\DataReferenceInterface::getTarget(). + * {@inheritdoc} */ public function getTarget() { if (!isset($this->target)) { // If we have a valid reference, return the entity object which is typed // data itself. If the reference is not valid, use the typed data API to // return an abstract type object so that the metadata is still available. - if ($id = $this->getSource()->getValue()) { - $this->target = entity_load($this->definition['constraints']['EntityType'], $id); + if (isset($this->id)) { + $this->target = entity_load($this->definition['constraints']['EntityType'], $this->id); } if (!$this->target) { - $this->target = typed_data()->create($this->getTargetDefinition(), NULL); + // @todo: fix entity constructor and abstract type class. + $this->target = new Entity($this->getTargetDefinition()); + //$this->target = typed_data()->create($this->getTargetDefinition(), NULL); } } return $this->target; } /** - * Implements \Drupal\Core\TypedData\DataReferenceInterface::getTargetIdentifier(). + * {@inheritdoc} */ public function getTargetIdentifier() { - if ($target_value = $this->getValue()) { - return $target_value->id(); + if (isset($this->id)) { + return $this->id; + } + elseif ($entity = $this->getValue()) { + return $entity->id(); } } /** - * Overrides \Drupal\Core\TypedData\TypedData::getValue(). + * {@inheritdoc} + * + * @return \Drupal\Core\Entity\EntityInterface|null */ public function getValue() { // If we have a valid reference, return the entity object, otherwise NULL. $target = $this->getTarget(); - return !$target->isempty() ? $target : NULL; + return !$target->isEmpty() ? $target : NULL; } /** - * Overrides \Drupal\Core\TypedData\TypedData::setValue(). + * {@inheritdoc} * * Both the entity ID and the entity object may be passed as value. */ public function setValue($value, $notify = TRUE) { - // If we have already a typed data object for the target, clear it. unset($this->target); + unset($this->id); - // Support passing in the entity object. - if ($value instanceof EntityInterface) { + // Support passing in the entity ID. + if (!isset($value) || $value instanceof EntityInterface) { $this->target = $value; - $value = $value->id(); } - elseif (isset($value) && !(is_scalar($value) && !empty($this->definition['constraints']['EntityType']))) { + elseif (!is_scalar($value) || empty($this->definition['constraints']['EntityType'])) { throw new InvalidArgumentException('Value is not a valid entity.'); } - // Now update the value in the source property. - $this->getSource()->setValue($value, $notify); + else { + $this->id = $value; + } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** - * Overrides \Drupal\Core\TypedData\TypedData::getString(). + * {@inheritdoc} */ public function getString() { if ($entity = $this->getValue()) { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php index ffbf41f..cac3875 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php @@ -56,7 +56,6 @@ public function getPropertyDefinitions() { // The entity object is computed out of the entity ID. 'computed' => TRUE, 'read-only' => FALSE, - 'settings' => array('source' => 'target_id'), ); if (isset($this->definition['settings']['target_bundle'])) { static::$propertyDefinitions[$key]['entity']['constraints']['Bundle'] = $this->definition['settings']['target_bundle']; @@ -93,15 +92,35 @@ public function __isset($property_name) { * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the entity property, if no array is - // given. if (isset($values) && !is_array($values)) { - $values = array('entity' => $values); + // Directly update the property instead of invoking the parent, so it can + // handle objects and IDs. + $this->properties['entity']->setValue($values, $notify); + // If notify was FALSE, ensure the target_id property gets synched. + if (!$notify) { + $this->set('target_id', $this->properties['entity']->getTargetIdentifier(), FALSE); + } + } + else { + // Make sure that the 'entity' property gets set as 'target_id'. + if (isset($values['target_id']) && !isset($values['entity'])) { + $values['entity'] = $values['target_id']; + } + parent::setValue($values, $notify); + } + } + + /** + * {@inheritdoc} + */ + public function onChange($property_name) { + // Make sure that the target ID and the target property stay in sync. + if ($property_name == 'target_id') { + $this->properties['entity']->setValue($this->target_id, FALSE); } - // Make sure that the 'entity' property gets set as 'target_id'. - if (isset($values['target_id']) && !isset($values['entity'])) { - $values['entity'] = $values['target_id']; + elseif ($property_name == 'entity') { + $this->set('target_id', $this->properties['entity']->getTargetIdentifier(), FALSE); } - parent::setValue($values, $notify); + parent::onChange($property_name); } } diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php index 4dc7657..bfdf497 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php @@ -73,11 +73,11 @@ public function getValue() { * Overrides \Drupal\Core\TypedData\TypedData::setValue(). */ public function setValue($values, $notify = TRUE) { - // Notify the parent of any changes to be made. + $this->fields = $values; + // Notify the parent of any changes. if ($notify && isset($this->parent)) { $this->parent->onChange($this->name); } - $this->fields = $values; } /** diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Type/Field.php index 5d0a4ff..58f3ffc 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Field.php @@ -67,10 +67,6 @@ public function getValue() { * Overrides \Drupal\Core\TypedData\ItemList::setValue(). */ public function setValue($values, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } if (!isset($values) || $values === array()) { $this->list = $values; } @@ -98,6 +94,10 @@ public function setValue($values, $notify = TRUE) { } } } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** diff --git a/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php b/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php index f888b5c..9d286ca 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php @@ -51,15 +51,35 @@ public function getPropertyDefinitions() { * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the language property, if no array - // is given. if (isset($values) && !is_array($values)) { - $values = array('language' => $values); + // Directly update the property instead of invoking the parent, so it can + // handle objects and IDs. + $this->properties['language']->setValue($values, $notify); + // If notify was FALSE, ensure the value property gets synched. + if (!$notify) { + $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE); + } } - // Make sure that the 'language' property gets set as 'value'. - if (isset($values['value']) && !isset($values['language'])) { - $values['language'] = $values['value']; + else { + // Make sure that the 'language' property gets set as 'value'. + if (isset($values['value']) && !isset($values['language'])) { + $values['language'] = $values['value']; + } + parent::setValue($values, $notify); } - parent::setValue($values, $notify); + } + + /** + * {@inheritdoc} + */ + public function onChange($property_name) { + // Make sure that the value and the language property stay in sync. + if ($property_name == 'value') { + $this->properties['language']->setValue($this->value, FALSE); + } + elseif ($property_name == 'language') { + $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE); + } + parent::onChange($property_name); } } diff --git a/core/lib/Drupal/Core/Entity/Field/Type/LanguageReference.php b/core/lib/Drupal/Core/Entity/Field/Type/LanguageReference.php new file mode 100644 index 0000000..fdae57d --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Field/Type/LanguageReference.php @@ -0,0 +1,41 @@ + 'language', + ); + } + + /** + * {@inheritdoc} + */ + public function getTargetIdentifier() { + if ($language = $this->getValue()) { + return $language->langcode; + } + } +} diff --git a/core/lib/Drupal/Core/TypedData/DataReferenceBase.php b/core/lib/Drupal/Core/TypedData/DataReferenceBase.php index 2cf6ce6..38fdf88 100644 --- a/core/lib/Drupal/Core/TypedData/DataReferenceBase.php +++ b/core/lib/Drupal/Core/TypedData/DataReferenceBase.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\TypedData\DataReferenceInterface. + * Contains \Drupal\Core\TypedData\DataReferenceBase. */ namespace Drupal\Core\TypedData; @@ -13,9 +13,6 @@ * Implementing classes have to implement at least * \Drupal\Core\TypedData\DataReferenceInterface::getTargetDefinition() and * \Drupal\Core\TypedData\DataReferenceInterface::getTargetIdentifier(). - * - * Required settings (below the definition's 'settings' key) are: - * - source: The langcode property used to load the language object. */ abstract class DataReferenceBase extends TypedData implements DataReferenceInterface { @@ -27,54 +24,34 @@ protected $target; /** - * Implements \Drupal\Core\TypedData\DataReferenceInterface::getTarget(). + * {@inheritdoc} */ public function getTarget() { - if (!isset($this->target)) { - $this->target = typed_data()->create($this->getTargetDefinition(), $this->getSource()->getValue()); - } return $this->target; } /** - * Overrides TypedData::getValue(). + * {@inheritdoc} */ public function getValue() { return $this->getTarget()->getValue(); } /** - * Helper to get the typed data object holding the source value. - * - * @return \Drupal\Core\TypedData\TypedDataInterface - */ - protected function getSource() { - if (empty($this->definition['settings']['source'])) { - throw new DataDefinitionException("Missing 'source' setting."); - } - return $this->parent->get($this->definition['settings']['source']); - } - - /** - * Overrides TypedData::setValue(). - * - * Both the langcode and the language object may be passed as value. + * {@inheritdoc} */ public function setValue($value, $notify = TRUE) { - // If we have already a typed data object for the target, clear it and start - // with a new object. That way we do not change the value of a object which - // might be referenced elsewhere also. - unset($this->target); - $target = $this->getTarget(); - // Set the value on the target so we can retrieve its identifier. - $target->setValue($value, $notify); - $this->getSource()->setValue($this->getTargetIdentifier(), $notify); + $this->target = typed_data()->create($this->getTargetDefinition(), $value); + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** - * Overrides TypedData::getString(). + * {@inheritdoc} */ public function getString() { - return (string) $this->getTargetIdentifier(); + return (string) $this->getType() . ':' . $this->getTargetIdentifier(); } } diff --git a/core/lib/Drupal/Core/TypedData/DataReferenceInterface.php b/core/lib/Drupal/Core/TypedData/DataReferenceInterface.php index d8df232..f5259d9 100644 --- a/core/lib/Drupal/Core/TypedData/DataReferenceInterface.php +++ b/core/lib/Drupal/Core/TypedData/DataReferenceInterface.php @@ -31,7 +31,7 @@ public function getTarget(); /** * Gets the identifier of the referenced data. * - * @return mixed + * @return int|string * The identifier of the referenced data. */ public function getTargetIdentifier(); diff --git a/core/lib/Drupal/Core/TypedData/ItemList.php b/core/lib/Drupal/Core/TypedData/ItemList.php index 88af366..cfc5655 100644 --- a/core/lib/Drupal/Core/TypedData/ItemList.php +++ b/core/lib/Drupal/Core/TypedData/ItemList.php @@ -42,10 +42,6 @@ public function getValue() { * An array of values of the field items, or NULL to unset the field. */ public function setValue($values, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } if (!isset($values) || $values === array()) { $this->list = $values; } @@ -72,6 +68,10 @@ public function setValue($values, $notify = TRUE) { } } } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** diff --git a/core/lib/Drupal/Core/TypedData/Type/Binary.php b/core/lib/Drupal/Core/TypedData/Type/Binary.php index f9c4985..b58a8e2 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Binary.php +++ b/core/lib/Drupal/Core/TypedData/Type/Binary.php @@ -51,10 +51,6 @@ public function getValue() { * Supports a PHP file resource or a (absolute) stream resource URI as value. */ public function setValue($value, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } if (!isset($value)) { $this->handle = NULL; $this->uri = NULL; @@ -68,6 +64,10 @@ public function setValue($value, $notify = TRUE) { else { $this->handle = $value; } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** diff --git a/core/lib/Drupal/Core/TypedData/Type/Date.php b/core/lib/Drupal/Core/TypedData/Type/Date.php index c9b8c6b..20e27fe 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Date.php +++ b/core/lib/Drupal/Core/TypedData/Type/Date.php @@ -32,10 +32,6 @@ class Date extends TypedData { * Overrides TypedData::setValue(). */ public function setValue($value, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } // Don't try to create a date from an empty value. // It would default to the current time. if (!isset($value)) { @@ -44,5 +40,9 @@ public function setValue($value, $notify = TRUE) { else { $this->value = $value instanceOf DrupalDateTime ? $value : new DrupalDateTime($value); } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } } diff --git a/core/lib/Drupal/Core/TypedData/Type/Duration.php b/core/lib/Drupal/Core/TypedData/Type/Duration.php index 52ba97d..64e1f4a 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Duration.php +++ b/core/lib/Drupal/Core/TypedData/Type/Duration.php @@ -32,10 +32,6 @@ class Duration extends TypedData { * Overrides TypedData::setValue(). */ public function setValue($value, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } // Catch any exceptions thrown due to invalid values being passed. try { if ($value instanceof DateInterval || !isset($value)) { @@ -61,6 +57,10 @@ public function setValue($value, $notify = TRUE) { // validation fail. $this->value = $e; } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** diff --git a/core/lib/Drupal/Core/TypedData/Type/Language.php b/core/lib/Drupal/Core/TypedData/Type/Language.php index a140a17..1b3a2af 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Language.php +++ b/core/lib/Drupal/Core/TypedData/Type/Language.php @@ -8,7 +8,6 @@ namespace Drupal\Core\TypedData\Type; use InvalidArgumentException; -use Drupal\Core\Language\Language as LanguageObject; use Drupal\Core\TypedData\TypedData; /** @@ -28,15 +27,20 @@ class Language extends TypedData { protected $langcode; /** + * @var \Drupal\Core\Language + */ + protected $language; + + /** * Overrides TypedData::getValue(). + * + * @return \Drupal\Core\Language\Language|null */ public function getValue() { - if (!empty($this->definition['settings']['langcode source'])) { - $this->langcode = $this->parent->__get($this->definition['settings']['langcode source']); - } - if ($this->langcode) { - return language_load($this->langcode); + if (!isset($this->language) && $this->langcode) { + $this->language = language_load($this->langcode); } + return $this->language; } /** @@ -47,23 +51,18 @@ public function getValue() { public function setValue($value, $notify = TRUE) { // Support passing language objects. if (is_object($value)) { - $value = $value->langcode; + $this->language = $value; } elseif (isset($value) && !is_scalar($value)) { - // @todo: Move this to a validation constraint. throw new InvalidArgumentException('Value is no valid langcode or language object.'); } - // Update the 'langcode source' property, if given. - if (!empty($this->definition['settings']['langcode source'])) { - $this->parent->__set($this->definition['settings']['langcode source'], $value, $notify); - } else { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } $this->langcode = $value; } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** diff --git a/core/lib/Drupal/Core/TypedData/Type/LanguageReference.php b/core/lib/Drupal/Core/TypedData/Type/LanguageReference.php deleted file mode 100644 index 48f0384..0000000 --- a/core/lib/Drupal/Core/TypedData/Type/LanguageReference.php +++ /dev/null @@ -1,41 +0,0 @@ - 'language', - ); - } - - /** - * Implements \Drupal\Core\TypedData\DataReferenceInterface::getTargetIdentifier(). - */ - public function getTargetIdentifier() { - if ($target_value = $this->getTarget()->getValue()) { - return $target_value->langcode; - } - } -} diff --git a/core/lib/Drupal/Core/TypedData/Type/Map.php b/core/lib/Drupal/Core/TypedData/Type/Map.php index da20e96..7bf535f 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Map.php +++ b/core/lib/Drupal/Core/TypedData/Type/Map.php @@ -78,10 +78,6 @@ public function setValue($values, $notify = TRUE) { if (isset($values) && !is_array($values)) { throw new \InvalidArgumentException("Invalid values given. Values must be represented as an associative array."); } - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } $this->values = $values; // Update any existing property objects. @@ -92,6 +88,10 @@ public function setValue($values, $notify = TRUE) { } $property->setValue($value, FALSE); } + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); + } } /** @@ -125,16 +125,16 @@ public function get($property_name) { * Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). */ public function set($property_name, $value, $notify = TRUE) { - // Notify the parent of any changes to be made. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } if ($this->getPropertyDefinition($property_name)) { - $this->get($property_name)->setValue($value); + $this->get($property_name)->setValue($value, $notify); } else { // Just set the plain value, which allows adding a new entry to the map. $this->values[$property_name] = $value; + // Directly notify ourselves. + if ($notify) { + $this->onChange($property_name, $value); + } } } diff --git a/core/lib/Drupal/Core/TypedData/TypedData.php b/core/lib/Drupal/Core/TypedData/TypedData.php index e9558f3..6930417 100644 --- a/core/lib/Drupal/Core/TypedData/TypedData.php +++ b/core/lib/Drupal/Core/TypedData/TypedData.php @@ -81,11 +81,11 @@ public function getValue() { * Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). */ public function setValue($value, $notify = TRUE) { - // Notify the parent of any changes to be made. + $this->value = $value; + // Notify the parent of any changes. if ($notify && isset($this->parent)) { $this->parent->onChange($this->name); } - $this->value = $value; } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index acd78c0..a16ebae 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -377,7 +377,7 @@ protected function assertIntrospection($entity_type) { $userref_properties = $entity->user_id->getPropertyDefinitions(); $this->assertEqual($userref_properties['target_id']['type'], 'integer', $entity_type .': Entity id property of the user found.'); - $this->assertEqual($userref_properties['entity']['type'], 'entity', $entity_type .': Entity reference property of the user found.'); + $this->assertEqual($userref_properties['entity']['type'], 'entity_reference', $entity_type .': Entity reference property of the user found.'); $textfield_properties = $entity->field_test_text->getPropertyDefinitions(); $this->assertEqual($textfield_properties['value']['type'], 'string', $entity_type .': String value property of the test-text field found.'); @@ -566,7 +566,10 @@ public function testEntityConstraintValidation() { $violations = $reference->validate(); $this->assertEqual($violations->count(), 1); - $node->type = 'article'; + $node = entity_create('node', array( + 'type' => 'article', + 'uid' => $user->id(), + )); $node->save(); $reference->setValue($node); $violations = $reference->validate(); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 10ede85..abc3355 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2325,7 +2325,7 @@ function system_data_type_info() { ), 'language_reference' => array( 'label' => t('Language reference'), - 'class' => '\Drupal\Core\TypedData\Type\LanguageReference', + 'class' => '\Drupal\Core\Entity\Field\Type\LanguageReference', ), 'entity' => array( 'label' => t('Entity'),