Problem/Motivation
When views are configured to display fields, and 'Rendered entity' is added as one of the fields, if an entity has any translations, for each view row that display that entity or its translation, the rendered entity displayed will ignore the 'Rendering language' configuration of the view display. A good example of such a view is the media_library view in the media_library module.
Steps to reproduce:
- On a multilingual site, configure a content type to be translatable.
- Create a node of that type.
- Add a translation of that node, and change the field values of the translation so differences are obvious.
- Create a content view.
- Configure the view to show fields.
- Add "Rendered entity" field
- Set the "Rendering Language" of the display to "Content language of view row".
- Preview the results, and observe that the node appears twice in the same language.
Proposed resolution
The view method of \Drupal\views\Plugin\views\field\RenderedEntity does not pass in a langcode to $view_builder->view(), so the entity is rendered per the site content language negotiation configuration.
Getting the langcode from the entity translation renderer and passing it into $view_builder->view() should provide the correct rendering language.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff-3045344-3-6.txt | 735 bytes | godotislate |
| #6 | 3045344-6.patch | 15.14 KB | godotislate |
| #3 | 3045344-3.patch | 15.17 KB | godotislate |
| #3 | interdiff_2-3.txt | 642 bytes | godotislate |
| #2 | 3045344-2.patch | 14.4 KB | godotislate |
Comments
Comment #2
godotislateHere's a failing test.
Comment #3
godotislatePatch with fix.
Comment #4
godotislateComment #5
dabblela commentedCame across this as well - I'm trying to keep the admin interface language separate from the content rendering language.
Just curious about this - it looks like
$entity = $this->getEntityTranslation($this->getEntity($values), $values);already calls$this->getEntityTranslationRenderer()so I wonder if this could be shortened to:Comment #6
godotislateI think that should work. My only thought is that
$entity->language()->getId()might not be the same as the$this->getEntityTranslationRenderer()->getLangcode($values), because if the entity does not have a translation in that language, the entity will be in a fallback language. But that should be fine, because that would be the result anyway.Updated patch.
Comment #7
anybodyI think this is a duplicate of #2925816: Views plugin "Rendered Entity" must add langcode in render function.
@godotislate: That other issue needs tests so if you'd be so nice to jump in, we might have a solution which can be committed to 8.8.x ASAP. :)
Closing this as duplicate.