Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     if (empty($values['data'])) {
         $values['data'] = NULL;
     } else {
         $deserialized_data = unserialize((string) $values['data']);
         $values['data'] = is_array($deserialized_data) ? $deserialized_data : NULL;
     }
     parent::setValue($values, $notify);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Unserialize the values.
     // @todo The storage controller should take care of this, see
     //   SqlContentEntityStorage::loadFieldItems, see
     //   https://www.drupal.org/node/2414835
     if (isset($values['query']) && is_string($values['query'])) {
         $values['query'] = unserialize($values['query']);
     }
     parent::setValue($values, $notify);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the first property, if no array is
     // given.
     if (is_string($values)) {
         $values = unserialize($values);
         if (!is_array($values)) {
             $values = array();
         }
     }
     $values = array('value' => $values);
     parent::setValue($values, $notify);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the language property, if no array
     // is given as this handles language codes and objects.
     if (isset($values) && !is_array($values)) {
         $this->set('language', $values, $notify);
     } 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);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the language property, if no array
     // is given as this handles language codes and objects.
     if (isset($values) && !is_array($values)) {
         // Directly update the property instead of invoking the parent, so that
         // the language property can take care of updating the language code
         // property.
         $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);
         }
     } 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);
     }
 }
Ejemplo n.º 6
0
 /**
  * Overrides \Drupal\Core\TypedData\FieldItemBase::setValue().
  *
  * @param array|null $values
  *   An array of property values.
  */
 public function setValue($values, $notify = TRUE)
 {
     parent::setValue($values);
     $this->populateComputedValues();
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the main property, if no array is
     // given.
     if (isset($values) && !is_array($values)) {
         $values = [static::mainPropertyName() => $values];
     }
     if (isset($values)) {
         $values += ['options' => []];
     }
     // Unserialize the values.
     // @todo The storage controller should take care of this, see
     //   SqlContentEntityStorage::loadFieldItems, see
     //   https://www.drupal.org/node/2414835
     if (is_string($values['options'])) {
         $values['options'] = unserialize($values['options']);
     }
     parent::setValue($values, $notify);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     if (isset($values) && !is_array($values)) {
         // If either a scalar or an object was passed as the value for the item,
         // assign it to the 'entity' property since that works for both cases.
         $this->set('entity', $values, $notify);
     } else {
         parent::setValue($values, FALSE);
         // Support setting the field item with only one property, but make sure
         // values stay in sync if only property is passed.
         if (isset($values['target_id']) && !isset($values['entity'])) {
             $this->onChange('target_id', FALSE);
         } elseif (!isset($values['target_id']) && isset($values['entity'])) {
             $this->onChange('entity', FALSE);
         } elseif (isset($values['target_id']) && isset($values['entity'])) {
             // If both properties are passed, verify the passed values match. The
             // only exception we allow is when we have a new entity: in this case
             // its actual id and target_id will be different, due to the new entity
             // marker.
             $entity_id = $this->get('entity')->getTargetIdentifier();
             if ($entity_id != $values['target_id'] && ($values['target_id'] != static::$NEW_ENTITY_MARKER || !$this->entity->isNew())) {
                 throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.');
             }
         }
         // Notify the parent if necessary.
         if ($notify && $this->parent) {
             $this->parent->onChange($this->getName());
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     if (isset($values) && !is_array($values)) {
         // If either a scalar or an object was passed as the value for the item,
         // assign it to the 'entity' property since that works for both cases.
         $this->set('entity', $values, $notify);
     } else {
         parent::setValue($values, FALSE);
         // Support setting the field item with only one property, but make sure
         // values stay in sync if only property is passed.
         // NULL is a valid value, so we use array_key_exists().
         if (is_array($values) && array_key_exists('target_id', $values) && !isset($values['entity'])) {
             $this->onChange('target_id', FALSE);
         } elseif (is_array($values) && !array_key_exists('target_id', $values) && isset($values['entity'])) {
             $this->onChange('entity', FALSE);
         } elseif (is_array($values) && array_key_exists('target_id', $values) && isset($values['entity'])) {
             // If both properties are passed, verify the passed values match. The
             // only exception we allow is when we have a new entity: in this case
             // its actual id and target_id will be different, due to the new entity
             // marker.
             $entity_id = $this->get('entity')->getTargetIdentifier();
             // If the entity has been saved and we're trying to set both the
             // target_id and the entity values with a non-null target ID, then the
             // value for target_id should match the ID of the entity value.
             if (!$this->entity->isNew() && $values['target_id'] !== NULL && $entity_id !== $values['target_id']) {
                 throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.');
             }
         }
         // Notify the parent if necessary.
         if ($notify && $this->parent) {
             $this->parent->onChange($this->getName());
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     if (isset($values) && !is_array($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);
     }
 }