Problem/Motivation

Rendered entity in view doesn't respect the views row rendering language.

rendered entity in wrong language

Views setup:

  • Create a view of entity type media (using media 8.x-1.7 atm)
  • Add a display of type page and use the table format
  • Rendering Language: Content language of view row
  • Add field of type Rendered entity and select a view mode. Media: Rendered entity (view mode: field_preview)
  • Add a exposed filter for translation language

Entity (media) setup:

In the view I show media entities of the type 'media collection'.
Media collection has a entity reference to the media entity of type 'image' (for the teaser image of the collection)

  • Set the media entity to translatable
  • Select all fields to be translatable
  • On the media entity 'image' set the field that contains the image to translatable (including file, title, alt)

Proposed resolution

Pass the entity language id to the view builder in the render function of the plugin.

Drupal\views\Plugin\views\field\RenderedEntity on line 115:

$build += $view_builder->view($entity, $this->options['view_mode']);

should be:

$build += $view_builder->view($entity, $this->options['view_mode'], $entity->language()->getId());

renderd entity after passing langcode

Comments

jens.de.geit created an issue. See original summary.

jens.de.geit’s picture

StatusFileSize
new753 bytes
lendude’s picture

Status: Active » Needs review

Fix makes sense, lets see what the testbot thinks....

Status: Needs review » Needs work

The last submitted patch, 2: 2925816 - views_plugin_langcode.patch, failed testing. View results

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new753 bytes

Testbot doesn't like spaces in filenames....

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

mbovan’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

#5 works for me on D8 8.5.3.

Setting to needs work because of missing tests.

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.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new757 bytes

Reroll, still needs tests.

berdir’s picture

Version: 8.6.x-dev » 8.7.x-dev
rollingnet’s picture

I can confirm that the patch solves the issue.
Tested with Media Library view on Drupal 8.7.1
A reroll of the patch should be done with the latest version of Drupal.

To me, it's ready to be marked as "fixed".

anybody’s picture

@rollingnet: No this is not fixed, because the fix has not been committed. But of course you can add your RTBC ;) And yes, this important patch fixes it.

@Berdir: Thank you so much - I had to search a lot to find this issue which was a major problem in several multilang D8 projects using rendered entity fields. Simply fix, HUGE improvement!

Confirming RTBC for #9. I tested it in 8.7 and 8.8.

anybody’s picture

Status: Needs review » Reviewed & tested by the community
anybody’s picture

Version: 8.7.x-dev » 8.8.x-dev
anybody’s picture

Here's a similar patch with tests included: #3045344: Views Rendered Entity field ignores the configured rendering language of the view display. I closed it as duplicate and informed the patch author to have a look at this issue. Would be lovely to see this committed to 8.8.x this way.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

Marking needs work, as we need to provide an automated test that proves the current problem and that the fix fixes it. (See also #7 and #9).

godotislate’s picture

StatusFileSize
new14.4 KB

Patch for failing test.

godotislate’s picture

StatusFileSize
new15.14 KB
new13.94 KB

Patch from #9 with tests.

godotislate’s picture

Status: Needs work » Needs review
mbovan’s picture

Issue tags: -Needs tests
mbovan’s picture

Status: Needs review » Reviewed & tested by the community

Tested locally and #18 works great.

gábor hojtsy’s picture

-        $build += $view_builder->view($entity, $this->options['view_mode']);
+        $build += $view_builder->view($entity, $this->options['view_mode'], $entity->language()->getId());

This of course works fine with Rendering Language: Content language of view row, does it work with other settings? The hardwired entity language getid makes me wonder. I looked at the tests and it is well tested with various other language rendering modes, so looks good. Will ask @plach for second opinion just to make sure I am not missing anything. This looks almost too simple a fix for such a bad bug :D

plach’s picture

@Gábor Hojtsy:

The fix is good: $entity->language()->getId() is the language of the entity translation instantiated using the configured entity translation renderer, so all cases are covered.

plach’s picture

Version: 8.8.x-dev » 8.7.x-dev

Bugs are fixed in the stable branch first.

  • plach committed 6dc692b on 8.8.x
    Issue #2925816 by godotislate, jens.de.geit, Berdir, Lendude, Anybody,...

  • plach committed eca8e5c on 8.7.x
    Issue #2925816 by godotislate, jens.de.geit, Berdir, Lendude, Anybody,...
plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6dc692b and pushed to 8.8.x and backported to 8.7.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.