public function EntityNG::__get

Implements the magic method for setting object properties.

Uses default language always. For compatibility mode to work this must return a reference.

File

drupal/core/lib/Drupal/Core/Entity/EntityNG.php, line 466
Contains \Drupal\Core\Entity\EntityNG.

Class

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

Namespace

Drupal\Core\Entity

Code

public function &__get($name) {

  // If this is an entity field, handle it accordingly. We first check whether
  // a field object has been already created. If not, we create one.
  if (isset($this->fields[$name][Language::LANGCODE_DEFAULT])) {
    return $this->fields[$name][Language::LANGCODE_DEFAULT];
  }

  // Inline getPropertyDefinition() to speed up things.
  if (!isset($this->fieldDefinitions)) {
    $this
      ->getPropertyDefinitions();
  }
  if (isset($this->fieldDefinitions[$name])) {
    $return = $this
      ->getTranslatedField($name, Language::LANGCODE_DEFAULT);
    return $return;
  }

  // Allow the EntityBCDecorator to directly access the values and fields.
  // @todo: Remove once the EntityBCDecorator gets removed.
  if ($name == 'values' || $name == 'fields') {
    return $this->{$name};
  }

  // Else directly read/write plain values. That way, non-field entity
  // properties can always be accessed directly.
  if (!isset($this->values[$name])) {
    $this->values[$name] = NULL;
  }
  return $this->values[$name];
}