You are here

public function ContentEntityBase::__set in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::__set()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::__set()

Implements the magic method for setting object properties.

Uses default language always.

File

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

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);
    }
    else {
      $this
        ->getTranslatedField($name, $this->activeLangcode)
        ->setValue($value);
    }
  }
  elseif ($name == 'translations') {
    $this->translations = $value;
  }
  else {
    $this->values[$name] = $value;
  }
}