protected function EntityNG::getTranslatedField

Gets a translated field.

Return value

\Drupal\Core\Entity\Field\FieldInterface

3 calls to EntityNG::getTranslatedField()
EntityNG::get in drupal/core/lib/Drupal/Core/Entity/EntityNG.php
Implements \Drupal\Core\TypedData\ComplexDataInterface::get().
EntityNG::getTranslation in drupal/core/lib/Drupal/Core/Entity/EntityNG.php
Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation().
EntityNG::__get in drupal/core/lib/Drupal/Core/Entity/EntityNG.php
Implements the magic method for setting object properties.

File

drupal/core/lib/Drupal/Core/Entity/EntityNG.php, line 217
Contains \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->fields to speed-up further look-ups and to keep track of
  // fields objects, possibly holding changes to field values.
  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 fields are always stored with
    // Language::LANGCODE_DEFAULT as key.
    if ($langcode != Language::LANGCODE_DEFAULT && empty($definition['translatable'])) {
      $this->fields[$property_name][$langcode] = $this
        ->getTranslatedField($property_name, Language::LANGCODE_DEFAULT);
    }
    else {
      $value = NULL;
      if (isset($this->values[$property_name][$langcode])) {
        $value = $this->values[$property_name][$langcode];
      }
      $this->fields[$property_name][$langcode] = \Drupal::typedData()
        ->getPropertyInstance($this, $property_name, $value);
    }
  }
  return $this->fields[$property_name][$langcode];
}