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

Sets the data value.

Parameters

mixed|null $value: The value to set in the format as documented for the data type or NULL to unset the data value.

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.

Throws

\InvalidArgumentException If the value input is inappropriate.

\Drupal\Core\TypedData\Exception\ReadOnlyException If the data is read-only.

Overrides TypedDataInterface::setValue

1 call to TypedData::setValue()
TypedData::applyDefaultValue in core/lib/Drupal/Core/TypedData/TypedData.php
Applies the default value.
5 methods override TypedData::setValue()
ComputedFileUrl::setValue in core/modules/file/src/ComputedFileUrl.php
Sets the data value.
DataReferenceBase::setValue in core/lib/Drupal/Core/TypedData/DataReferenceBase.php
Sets the data value.
DateTimeComputed::setValue in core/modules/datetime/src/DateTimeComputed.php
Sets the data value.
PrimitiveBase::setValue in core/lib/Drupal/Core/TypedData/PrimitiveBase.php
Sets the data value.
TextProcessed::setValue in core/modules/text/src/TextProcessed.php
Sets the data value.

File

core/lib/Drupal/Core/TypedData/TypedData.php, line 101

Class

TypedData
The abstract base class for typed data.

Namespace

Drupal\Core\TypedData

Code

public function setValue($value, $notify = TRUE) {
  $this->value = $value;

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