By berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-beta15
Description:
#2513094: ContentEntityBase::getTranslatedField and ContentEntityBase::__clone break field reference to parent entity introduced a regression when displaying translated references in untranslated fields.
To fix that, a small API change for field formatter plugins is necessary:
- public function view(FieldItemListInterface $items);
+ public function view(FieldItemListInterface $items, $langcode = NULL);
- public function viewElements(FieldItemListInterface $items);
+ public function viewElements(FieldItemListInterface $items, $langcode);
Most field formatters only override viewElements(), all they have to do is add the new argument and pass it along to any other method that needs it - typically the EntityReferenceFormatterBase;;getEntititiesToView() method used by formatters for entity_reference fields (and sub-field types like file or image reference fields), which also gets the additional $langcode parameter.
/**
* {@inheritdoc}
*/
- public function viewElements(FieldItemListInterface $items) {
+ public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$output_as_link = $this->getSetting('link');
- foreach ($this->getEntitiesToView($items) as $delta => $entity) {
+ foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
$label = $entity->label();
// If the link is to be displayed and the entity has a uri, display a
// link.
Impacts:
Module developers