commit 6169ea529debed8f36345f229c0c2cae72f03ab1 Author: fago Date: Wed Mar 27 17:48:54 2013 +0100 Addressing berdir review. diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 73d507d..01966c7 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -60,6 +60,7 @@ public function setValue($values, $notify = TRUE) { $value = $values[$name]; } $property->setValue($value, FALSE); + unset($this->values[$name]); } } diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php index c0e15a6..17a57da 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php @@ -89,26 +89,14 @@ public function __isset($property_name) { public function setValue($values, $notify = TRUE) { // Treat the values as property value of the first property, if no array is // given. - if (!is_array($values)) { + if (isset($values) && !is_array($values)) { $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, except of 'entity'. - foreach ($this->properties as $name => $property) { - if ($name != 'entity') { - $value = NULL; - if (isset($values[$name])) { - $value = $values[$name]; - } - $property->setValue($value, 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']; } + parent::setValue($values, $notify); } } diff --git a/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php b/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php index d78c0c0..613f525 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php @@ -52,26 +52,14 @@ public function getPropertyDefinitions() { public function setValue($values, $notify = TRUE) { // Treat the values as property value of the first property, if no array is // given. - if (!is_array($values)) { + if (isset($values) && !is_array($values)) { $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, except of 'entity'. - foreach ($this->properties as $name => $property) { - if ($name != 'language') { - $value = NULL; - if (isset($values[$name])) { - $value = $values[$name]; - } - $property->setValue($value, FALSE); - } + // 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); } } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataInterface.php b/core/lib/Drupal/Core/TypedData/TypedDataInterface.php index ac2297d..e598f9f 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataInterface.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataInterface.php @@ -45,8 +45,8 @@ public function getValue(); * unset the data value. * @param bool * (optional) Whether to notify the parent object of the change. Defaults to - * TRUE. Usually parent objects should be notified unless the method is - * invoked by the parent itself. + * TRUE. If a property is updated from a parent object, set it to FALSE to + * avoid being notified again. * * @throws \Drupal\Core\TypedData\ReadOnlyException * If the data is read-only. diff --git a/core/modules/file/lib/Drupal/file/Type/FileItem.php b/core/modules/file/lib/Drupal/file/Type/FileItem.php index 85d4025..64815fe 100644 --- a/core/modules/file/lib/Drupal/file/Type/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Type/FileItem.php @@ -63,26 +63,14 @@ public function getPropertyDefinitions() { public function setValue($values, $notify = TRUE) { // Treat the values as property value of the first property, if no array is // given. - if (!is_array($values)) { + if (isset($values) && !is_array($values)) { $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, except of 'entity'. - foreach ($this->properties as $name => $property) { - if ($name != 'entity') { - $value = NULL; - if (isset($values[$name])) { - $value = $values[$name]; - } - $property->setValue($value, FALSE); - } + // Make sure that the 'entity' property gets set as 'fid'. + if (isset($values['fid']) && !isset($values['entity'])) { + $values['entity'] = $values['fid']; } + parent::setValue($values, $notify); } } diff --git a/core/modules/image/lib/Drupal/image/Type/ImageItem.php b/core/modules/image/lib/Drupal/image/Type/ImageItem.php index 72bf09c..03d48c9 100644 --- a/core/modules/image/lib/Drupal/image/Type/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Type/ImageItem.php @@ -65,41 +65,19 @@ public function getPropertyDefinitions() { } /** - * Overrides \Drupal\Core\Entity\Field\FieldItemBase::setValue(). + * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ - public function setValue($values) { - // Treat the values as property value of the entity field, if no array - // is given. - if (!is_array($values)) { - $values = array('entity' => $values); + public function setValue($values, $notify = TRUE) { + // Treat the values as property value of the first property, if no array is + // given. + if (isset($values) && !is_array($values)) { + $keys = array_keys($this->getPropertyDefinitions()); + $values = array($keys[0] => $values); } - - foreach (array('alt', 'title', 'width', 'height') as $property) { - if (isset($values[$property])) { - $this->properties[$property]->setValue($values[$property]); - unset($values[$property]); - } - } - - // Entity is computed out of the ID, so we only need to update the ID. Only - // set the entity field if no ID is given. - if (isset($values['fid'])) { - $this->properties['fid']->setValue($values['fid']); - } - elseif (isset($values['entity'])) { - $this->properties['entity']->setValue($values['entity']); - } - else { - $this->properties['entity']->setValue(NULL); - } - - unset($values['fid'], $values['entity']); - // @todo These properties are sometimes set due to being present in form - // values. Needs to be cleaned up somewhere. - unset($values['display'], $values['description'], $values['upload_button'], $values['remove_button'], $values['upload']); - if ($values) { - throw new \InvalidArgumentException('Property ' . key($values) . ' is unknown.'); + // Make sure that the 'entity' property gets set as 'fid'. + if (isset($values['fid']) && !isset($values['entity'])) { + $values['entity'] = $values['fid']; } + parent::setValue($values, $notify); } - } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php index d9ee0c9..395fe88 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php @@ -55,26 +55,14 @@ public function getPropertyDefinitions() { public function setValue($values, $notify = TRUE) { // Treat the values as property value of the first property, if no array is // given. - if (!is_array($values)) { + if (isset($values) && !is_array($values)) { $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, except of 'entity'. - foreach ($this->properties as $name => $property) { - if ($name != 'entity') { - $value = NULL; - if (isset($values[$name])) { - $value = $values[$name]; - } - $property->setValue($value, FALSE); - } + // Make sure that the 'entity' property gets set as 'tid'. + if (isset($values['tid']) && !isset($values['entity'])) { + $values['entity'] = $values['tid']; } + parent::setValue($values, $notify); } }