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
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | entiy_revisions_blocks_always_default_language-2949138-5.patch | 1.07 KB | dimr |
Comments
Comment #2
Jorge Navarro commentedI 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.
Comment #3
Jorge Navarro commentedComment #4
dimr commentedIn 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 [▶]
]
Comment #5
dimr commentedI 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.
Comment #6
sleepingmonkShould this be listed under "Core Drupal" rather than ERR, so we can get some core dev eyes on it?
Comment #7
dimr commentedComment #9
steven buteneers commentedThis 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.
Comment #10
steven buteneers commentedComment #11
hchonovThis however returns the current interface language :). You would need to provide
LanguageInterface::TYPE_CONTENTas parameter to the method in order to retrieve the current content language.Comment #12
amateescu commented#9 sounds like we can close this as a duplicate of #2955392: EntityViewBuilder::viewField() does not respect entity current language when used with an entity reference field.