protected function EntityNG::getTranslatedField

Gets a translated field.

Return value

\Drupal\Core\Entity\Field\FieldInterface

2 calls to EntityNG::getTranslatedField()
EntityNG::get in drupal/core/lib/Drupal/Core/Entity/EntityNG.php
Implements ComplexDataInterface::get().
EntityNG::getTranslation in drupal/core/lib/Drupal/Core/Entity/EntityNG.php
Implements TranslatableInterface::getTranslation().

File

drupal/core/lib/Drupal/Core/Entity/EntityNG.php, line 95
Definition of Drupal\Core\Entity\EntityNG.

Class

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

Namespace

Drupal\Core\Entity

Code

protected function getTranslatedField($property_name, $langcode) {

  // Populate $this->properties to fasten further lookups and to keep track of
  // property objects, possibly holding changes to properties.
  if (!isset($this->fields[$property_name][$langcode])) {
    $definition = $this
      ->getPropertyDefinition($property_name);
    if (!$definition) {
      throw new InvalidArgumentException('Field ' . check_plain($property_name) . ' is unknown.');
    }

    // Non-translatable properties always use default language.
    if ($langcode != LANGUAGE_DEFAULT && empty($definition['translatable'])) {
      $this->fields[$property_name][$langcode] = $this
        ->getTranslatedField($property_name, LANGUAGE_DEFAULT);
    }
    else {
      $value = isset($this->values[$property_name][$langcode]) ? $this->values[$property_name][$langcode] : NULL;
      $context = array(
        'parent' => $this,
        'name' => $property_name,
      );
      $this->fields[$property_name][$langcode] = typed_data()
        ->create($definition, $value, $context);
    }
  }
  return $this->fields[$property_name][$langcode];
}