You are here

public function MapItem::setValue in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php \Drupal\Core\Field\Plugin\Field\FieldType\MapItem::setValue()
  2. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php \Drupal\Core\Field\Plugin\Field\FieldType\MapItem::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 FieldItemBase::setValue

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php, line 56

Class

MapItem
Defines the 'map' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public function setValue($values, $notify = TRUE) {
  $this->values = [];
  if (!isset($values)) {
    return;
  }
  if (!is_array($values)) {
    if ($values instanceof MapItem) {
      $values = $values
        ->getValue();
    }
    else {
      $values = unserialize($values, [
        'allowed_classes' => FALSE,
      ]);
    }
  }
  $this->values = $values;

  // Notify the parent of any changes.
  if ($notify && isset($this->parent)) {
    $this->parent
      ->onChange($this->name);
  }
}