function Map::setValue

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php \Drupal\Core\TypedData\Plugin\DataType\Map::setValue()
  2. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php \Drupal\Core\TypedData\Plugin\DataType\Map::setValue()
  3. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php \Drupal\Core\TypedData\Plugin\DataType\Map::setValue()

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

Parameters

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

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.

Overrides TypedData::setValue

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

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php, line 80

Class

Map
The "map" data type.

Namespace

Drupal\Core\TypedData\Plugin\DataType

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.");
    }
    $this->values = $values;
    // Update any existing property objects.
    foreach ($this->properties as $name => $property) {
        $value = $values[$name] ?? NULL;
        $property->setValue($value, FALSE);
        // Remove the value from $this->values to ensure it does not contain any
        // value for computed properties.
        unset($this->values[$name]);
    }
    // Notify the parent of any changes.
    if ($notify && isset($this->parent)) {
        $this->parent
            ->onChange($this->name);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.