function ContentEntityBase::__set
Implements the magic method for setting object properties.
Uses default language always.
Overrides EntityBase::__set
File
- 
              core/lib/ Drupal/ Core/ Entity/ ContentEntityBase.php, line 1121 
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
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;
  }
  elseif ($name == 'original') {
    parent::__set('original', $value);
  }
  else {
    $this->values[$name] = $value;
  }
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
