public function Map::setValue

Overrides \Drupal\Core\TypedData\TypedData::setValue().

Parameters

array|null $values: An array of property values.

Overrides TypedData::setValue

1 method overrides Map::setValue()
FieldItemBase::setValue in drupal/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php
Overrides \Drupal\Core\TypedData\TypedData::setValue().

File

drupal/core/lib/Drupal/Core/TypedData/Type/Map.php, line 77
Contains \Drupal\Core\TypedData\Type\Map.

Class

Map
The "map" data type.

Namespace

Drupal\Core\TypedData\Type

Code

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.
  foreach ($this->properties as $name => $property) {
    $value = NULL;
    if (isset($values[$name])) {
      $value = $values[$name];
    }
    $property
      ->setValue($value, FALSE);
  }
}