public function ContentEntityBase::__set

public ContentEntityBase::__set($name, $value)

Implements the magic method for setting object properties.

Uses default language always.

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 919

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function __set($name, $value) {
  // Inline getFieldDefinition() to speed things up.
  if (!isset($this->fieldDefinitions)) {
    $this->getFieldDefinitions();
  }
  // Handle Field API fields.
  if (isset($this->fieldDefinitions[$name])) {
    // Support setting values via property objects.
    if ($value instanceof TypedDataInterface) {
      $value = $value->getValue();
    }
    // If a FieldItemList object already exists, set its value.
    if (isset($this->fields[$name][$this->activeLangcode])) {
      $this->fields[$name][$this->activeLangcode]->setValue($value);
    }
    // If not, create one.
    else {
      $this->getTranslatedField($name, $this->activeLangcode)->setValue($value);
    }
  }
  // The translations array is unset when cloning the entity object, we just
  // need to restore it.
  elseif ($name == 'translations') {
    $this->translations = $value;
  }
  // Directly write non-field values.
  else {
    $this->values[$name] = $value;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityBase.php/function/ContentEntityBase::__set/8.1.x