diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 5a8d4ff..f91b8a9 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -89,7 +89,7 @@ public function get($property_name, $langcode = NULL) { * EntityInterface::set() implements support for fieldable entities, but * configuration entities are not fieldable. */ - public function set($property_name, $value, $langcode = NULL) { + public function set($property_name, $value, $langcode = NULL, $notify = TRUE) { // @todo: Add support for translatable properties being not fields. $this->{$property_name} = $value; } diff --git a/core/lib/Drupal/Core/Config/Schema/Mapping.php b/core/lib/Drupal/Core/Config/Schema/Mapping.php index e958f07..b7bddb3 100644 --- a/core/lib/Drupal/Core/Config/Schema/Mapping.php +++ b/core/lib/Drupal/Core/Config/Schema/Mapping.php @@ -52,7 +52,11 @@ public function get($property_name) { /** * Implements Drupal\Core\TypedData\ComplexDataInterface::set(). */ - public function set($property_name, $value) { + 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)) { diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 11934bf..c2f9d3a 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -191,7 +191,7 @@ public function get($property_name, $langcode = NULL) { /** * Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). */ - public function set($property_name, $value) { + public function set($property_name, $value, $notify = TRUE) { // @todo: Replace by EntityNG implementation once all entity types have been // converted to use the entity field API. $this->{$property_name} = $value; diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index 481f01a..95bd85d 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -229,7 +229,7 @@ public function get($property_name) { /** * Forwards the call to the decorated entity. */ - public function set($property_name, $value) { + public function set($property_name, $value, $notify = TRUE) { // Ensure this works with not yet defined fields. if (!isset($this->definitions[$property_name])) { return $this->__set($property_name, $value); diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 14403bb..9406927 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -179,8 +179,8 @@ protected function getTranslatedField($property_name, $langcode) { /** * Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). */ - public function set($property_name, $value) { - $this->get($property_name)->setValue($value); + public function set($property_name, $value, $notify = TRUE) { + $this->get($property_name)->setValue($value, FALSE); } /** diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 01966c7..1ea77ee 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -80,15 +80,15 @@ public function __get($name) { /** * Overrides \Drupal\Core\TypedData\Type\Map::set(). */ - public function set($property_name, $value) { + 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 (isset($this->properties[$property_name])) { - $this->properties[$property_name]->setValue($value); + $this->properties[$property_name]->setValue($value, FALSE); } else { - // Notify the parent of any changes to be made. - if (isset($this->parent)) { - $this->parent->onChange($this->name); - } // Just set the plain value, which allows adding a new entry to the map. $this->values[$property_name] = $value; } diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php index 17a57da..5b78a05 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityReferenceItem.php @@ -87,11 +87,10 @@ 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 first property, if no array is + // Treat the values as property value of the entity property, if no array is // given. if (isset($values) && !is_array($values)) { - $keys = array_keys($this->getPropertyDefinitions()); - $values = array($keys[0] => $values); + $values = array('entity' => $values); } // Make sure that the 'entity' property gets set as 'target_id'. if (isset($values['target_id']) && !isset($values['entity'])) { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php index 4765a54..84293c3 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php @@ -105,8 +105,8 @@ public function get($property_name) { /** * Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). */ - public function set($property_name, $value) { - $this->get($property_name)->setValue($value); + public function set($property_name, $value, $notify = TRUE) { + $this->get($property_name)->setValue($value, FALSE); } /** diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php index 92fab01..dad6a57 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityWrapper.php @@ -102,11 +102,7 @@ public function setValue($value, $notify = TRUE) { } // Update the 'id source' property, if given. if (!empty($this->definition['settings']['id source'])) { - // We only need to update the source, if we are not invoked from the - // parent, i.e. when notify is TRUE. - if ($notify) { - $this->parent->__set($this->definition['settings']['id source'], $value); - } + $this->parent->__set($this->definition['settings']['id source'], $value, $notify); } else { // Notify the parent of any changes to be made. @@ -150,8 +146,8 @@ public function get($property_name) { /** * Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). */ - public function set($property_name, $value) { - $this->get($property_name)->setValue($value); + public function set($property_name, $value, $notify = TRUE) { + $this->get($property_name)->setValue($value, FALSE); } /** diff --git a/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php b/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php index 613f525..2db12e1 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/LanguageItem.php @@ -50,11 +50,10 @@ public function getPropertyDefinitions() { * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the first property, if no array is - // given. + // Treat the values as property value of the language property, if no array + // is given. if (isset($values) && !is_array($values)) { - $keys = array_keys($this->getPropertyDefinitions()); - $values = array($keys[0] => $values); + $values = array('language' => $values); } // Make sure that the 'language' property gets set as 'value'. if (isset($values['value']) && !isset($values['language'])) { diff --git a/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php b/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php index e3a540b..595064e 100644 --- a/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php +++ b/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php @@ -44,6 +44,10 @@ public function get($property_name); * The name of the property to set; e.g., 'title' or 'name'. * @param $value * The value to set, or NULL to unset the property. + * @param bool $notify + * (optional) Whether to notify the parent object of the change. Defaults to + * TRUE. If the update stems from a parent object, set it to FALSE to avoid + * being notified again. * * @throws \InvalidArgumentException * If the specified property does not exist. @@ -51,7 +55,7 @@ public function get($property_name); * @return \Drupal\Core\TypedData\TypedDataInterface * The property object. */ - public function set($property_name, $value); + public function set($property_name, $value, $notify = TRUE); /** * Gets an array of property objects. diff --git a/core/lib/Drupal/Core/TypedData/Type/Language.php b/core/lib/Drupal/Core/TypedData/Type/Language.php index 1b72584..b910216 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Language.php +++ b/core/lib/Drupal/Core/TypedData/Type/Language.php @@ -62,11 +62,7 @@ public function setValue($value, $notify = TRUE) { } // Update the 'langcode source' property, if given. if (!empty($this->definition['settings']['langcode source'])) { - // We only need to update the source, if we are not invoked from the - // parent, i.e. when notify is TRUE. - if ($notify) { - $this->parent->__set($this->definition['settings']['langcode source'], $value); - } + $this->parent->__set($this->definition['settings']['langcode source'], $value, $notify); } else { // Notify the parent of any changes to be made. diff --git a/core/lib/Drupal/Core/TypedData/Type/Map.php b/core/lib/Drupal/Core/TypedData/Type/Map.php index 338ff8e..da20e96 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Map.php +++ b/core/lib/Drupal/Core/TypedData/Type/Map.php @@ -124,7 +124,11 @@ public function get($property_name) { /** * Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). */ - public function set($property_name, $value) { + 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); } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataInterface.php b/core/lib/Drupal/Core/TypedData/TypedDataInterface.php index e598f9f..dc313e3 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataInterface.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataInterface.php @@ -43,7 +43,7 @@ public function getValue(); * @param mixed|null $value * The value to set in the format as documented for the data type or NULL to * unset the data value. - * @param bool + * @param bool $notify * (optional) Whether to notify the parent object of the change. Defaults to * TRUE. If a property is updated from a parent object, set it to FALSE to * avoid being notified again. diff --git a/core/modules/file/lib/Drupal/file/Type/FileItem.php b/core/modules/file/lib/Drupal/file/Type/FileItem.php index 64815fe..0b2c74b 100644 --- a/core/modules/file/lib/Drupal/file/Type/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Type/FileItem.php @@ -61,11 +61,10 @@ public function getPropertyDefinitions() { * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the first property, if no array is + // Treat the values as property value of the entity property, if no array is // given. if (isset($values) && !is_array($values)) { - $keys = array_keys($this->getPropertyDefinitions()); - $values = array($keys[0] => $values); + $values = array('entity' => $values); } // Make sure that the 'entity' property gets set as 'fid'. if (isset($values['fid']) && !isset($values['entity'])) { diff --git a/core/modules/image/lib/Drupal/image/Type/ImageItem.php b/core/modules/image/lib/Drupal/image/Type/ImageItem.php index 03d48c9..f6cedf2 100644 --- a/core/modules/image/lib/Drupal/image/Type/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Type/ImageItem.php @@ -68,11 +68,10 @@ public function getPropertyDefinitions() { * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the first property, if no array is + // Treat the values as property value of the entity property, if no array is // given. if (isset($values) && !is_array($values)) { - $keys = array_keys($this->getPropertyDefinitions()); - $values = array($keys[0] => $values); + $values = array('entity' => $values); } // Make sure that the 'entity' property gets set as 'fid'. if (isset($values['fid']) && !isset($values['entity'])) { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php index 395fe88..b558d97 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php @@ -53,11 +53,10 @@ public function getPropertyDefinitions() { * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). */ public function setValue($values, $notify = TRUE) { - // Treat the values as property value of the first property, if no array is + // Treat the values as property value of the entity property, if no array is // given. if (isset($values) && !is_array($values)) { - $keys = array_keys($this->getPropertyDefinitions()); - $values = array($keys[0] => $values); + $values = array('entity' => $values); } // Make sure that the 'entity' property gets set as 'tid'. if (isset($values['tid']) && !isset($values['entity'])) { diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php index 79a7f99..95cf300 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -167,7 +167,7 @@ public function setStatus($status) { /** * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::set(). */ - public function set($property_name, $value) { + public function set($property_name, $value, $notify = TRUE) { if (property_exists($this->storage, $property_name)) { $this->storage->set($property_name, $value); }