Gets a translated field.
\Drupal\Core\Entity\Field\FieldInterface
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];
}