Problem/Motivation
We noticed some duplicates in one of our views.
It's a view that returns fields from relationships and uses grouping. The problem is that the view adds langcode columns to the GROUP BY even for fields that we don't want to add to the GROUP BY.
Steps to reproduce
I attached the YAML of a very simple view that reproduces the problem. It contains a relationship to an user and displays the user name.
If we set group_column: value on the user name field, it will generate this GROUP BY:
GROUP BY "users_field_data_node_field_data_name", "users_field_data_node_field_data_langcode"
This is fine and expected.
However, if we set group_column: entity_id, it generates this GROUP BY:
GROUP BY "users_field_data_node_field_data_langcode"
This is an unexpected behavior because I expected the users_field_data_node_field_data table to not be used in the GROUP BY at all.
I think it should only add the langcode column when another column of this table is added.
Proposed resolution
TranslationLanguageRenderer::query() should probably only be called when the corresponding EntityField is actually added to the query.
| Comment | File | Size | Author |
|---|---|---|---|
| views.view_.test.yml | 4.46 KB | prudloff |
Issue fork drupal-3362917
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3362917-translationlanguagerenderer-adds-langcode
changes, plain diff MR !4056
Comments
Comment #3
prudloff commentedComment #4
prudloff commentedComment #5
smustgrave commentedHave not yet reviewed
But fix seemed to cause some failures.
Also will need it's own test case.
Should also try and aim for 11.x as that's the current development branch.
Comment #8
prudloff commentedCalling
$this->getEntityFieldRenderer()->query()seems necessary because it does not only add the GROUP BY, it also adds the langcode in SELECT so the entity can be rendered in the correct language.And I can't reproduce the duplicate problem from the issue summary so I'm closing this.
I'll reopen if I manage to reproduce.
Comment #9
prudloff commentedI managed to reproduce my original duplicate problem and I think #2737619: Views entity reference relationships must join on langcode for translatable entities would be the correct way to fix this.