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