Steps to reproduce:

  • In a Drupal Multilanguage website create a content type B with some translatable fields.
  • Create another content type A with at least a field, named X for example, of "Entity Reference Revision" no translatable that links to contents of B.
  • Add the field X, in the content type A, to the "Manage Display" selecting "Render Entity" as "Format".
  • Add in the "Block Layout" a "Content Block" of the field X selecting "Render Entity".
  • Create a view showing the field X and display it as a block, add that view block in the "Block Layout".
  • Create a new node of B and another node of A, linking the field X to the node of B.
  • Create a translation of both nodes.
  • See the node of A with the NO default language selected, and observe that the Field X and the view Block are shown in the selected language, but the content block of the field X is shown in the default language

This affects that the fields "Entity Reference Revisions" are shown in a wrong language if it used Panelizer too.

I have done the same test with a field "Entity Reference" and with that, it works in all the cases, as a block, as a field and a view block.

EDITED:

I have realized that the language in
public function view(FieldItemListInterface $items, $langcode = NULL)
web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php was already "wrong" and that $langcode is coming from public function buildMultiple(array $entities) in web/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php

Comments

dimr created an issue. See original summary.

Jorge Navarro’s picture

I can confirm the issue. I run a test with paragraphs, and if the field is in a block, the output is always in the source language.

Jorge Navarro’s picture

Version: 8.x-1.4 » 8.x-1.x-dev
dimr’s picture

Priority: Normal » Major

In my case I am using symmetric translations in the paragraph, that means that the field paragraph in the main content type is not translatable but the fields of the paragraph type are translatable. I think that there is the error.

Debugging, and I have seen that in the template I get both languages for the same field, in this case, a field named "Title".

Using {{ vardumper(paragraph) }} in the template I got:

#values: array:24 [▼
"field_title" => array:2 [▼
"x-default" => array:1 [▼
0 => array:1 [▼
"value" => "Section Title Default Language"
]
]
"en" => array:1 [▼
0 => array:1 [▼
"value" => "Section Title Second Language"
]
]
]
]

But in the Fields is selecting the default language

#fields: array:8 [▼
"status" => array:1 [▶]
"parent_type" => array:1 [▶]
"parent_id" => array:1 [▶]
"field_content" => array:1 [▶]
"field_title" => array:1 [▼
"x-default" => FieldItemList {#4423 ▶}
]
"type" => array:1 [▶]
"field_background" => array:1 [▶]
"field_anchor_title" => array:1 [▶]
]

dimr’s picture

I have continued debugging and I have found a solution to my problem.

I have realized that the language in
public function view(FieldItemListInterface $items, $langcode = NULL)
web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php was already "wrong" and that $langcode is coming from public function buildMultiple(array $entities) in web/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php

Then I have decided to make the changes there, taking the current language always the entity has that language.
I have created a patch for that, it is a core patch, but I am not sure if it is a Drupal core or entity reference revision issue, that is why I am keeping this issue in this module.

sleepingmonk’s picture

Should this be listed under "Core Drupal" rather than ERR, so we can get some core dev eyes on it?

dimr’s picture

Project: Entity Reference Revisions » Drupal core
Version: 8.x-1.x-dev » 8.5.x-dev
Component: Code » entity system
Issue summary: View changes

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

steven buteneers’s picture

This is related to a core issue with EntityViewBuilder::viewField()

See: https://www.drupal.org/project/drupal/issues/2955392. The patches in this issue fix the problem in this issue.

hchonov’s picture

+++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php
@@ -254,7 +254,12 @@ public function buildMultiple(array $entities) {
+            $current_language = \Drupal::languageManager()->getCurrentLanguage();

This however returns the current interface language :). You would need to provide LanguageInterface::TYPE_CONTENT as parameter to the method in order to retrieve the current content language.

amateescu’s picture

Status: Active » Closed (duplicate)