function EntityAdapter::set

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::set()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::set()
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::set()

Sets a property value.

Parameters

$property_name: The name of the property to set; e.g., 'title' or 'name'.

$value: The value to set, or NULL to unset the property.

bool $notify: (optional) Whether to notify the parent object of the change. Defaults to TRUE. If the update stems from a parent object, set it to FALSE to avoid being notified again.

Return value

$this

Overrides ComplexDataInterface::set

1 method overrides EntityAdapter::set()
ConfigEntityAdapter::set in core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php
Sets a property value.

File

core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php, line 90

Class

EntityAdapter
Defines the "entity" data type.

Namespace

Drupal\Core\Entity\Plugin\DataType

Code

public function set($property_name, $value, $notify = TRUE) {
    if (!isset($this->entity)) {
        throw new MissingDataException("Unable to set property {$property_name} as no entity has been provided.");
    }
    if (!$this->entity instanceof FieldableEntityInterface) {
        throw new \InvalidArgumentException("Unable to set unknown property {$property_name}.");
    }
    // This will throw an exception for unknown fields.
    $this->entity
        ->set($property_name, $value, $notify);
    return $this;
}

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