Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294391

Views entity reference relationships must join on langcode for translatable entities

$
0
0

Problem/Motivation

(Why the issue was filed, steps to reproduce the problem, etc.)

Steps to reproduce

1) Create new node type (for example: referenced_page)
2) Navigate to admin/config/regional/content-language and set that node type to translatable
3) Create a piece of content of that node type (for example: This is the default language version of the referenced page)
4) Create another node type (for example: referencing_page)
5) Add an entity reference field to that node type that allows it to point to the referenced_page node type
6) Do NOT set that node type to be translatable (It doesn't actually matter if you do. You'll still run into the same problem. I'm just specifically addressing the point about having a non-translatable entity referencing a translatable entity. The heart of the issue is that the referenced entity is translatable).
7) Create a piece of content of the referencing page (for example: This is the default language of the referencing page)
8) Reference the first node type (for example, pointing to "This is the default language version of the referenced page.")
9) Create a block that uses: a contextual filter with a default argument of Content ID from URL; a relationship of "Content using {your_entity_reference_field}" and require the relationship; Title field (use the relationship) of referencing pages pointing to this referenced page.
10) Place the block in a region
11) Visit the "This is the default language version of the referenced page" node
12) Observe that there is only one title in the block
13) Add a translation "This is another language version of the referenced page"
14) Observe that the block now contains two titles.
15) Add another language to the site
16) Add a translation "This is a third language version of the referenced page"
17) Observe that there are now three titles in the block

Note: One workaround for the duplication is to use aggregation (for example Group column Entity ID or Language), although that's just masking the symptom and may have other undesirable side effects.

Proposed resolution

The primary key of an entity's data table is id, langcode. When joining on entity data tables as part of a Views relationship for an entity reference, Views only joins on the ID, however, not on the ID+langcode combination. This leads to duplicate results in case the respective entities are translated.

Remaining tasks

Modify the entity views data for all entity reference relationships to include an extra entry that additionally joins on the langcode. When joining from a non-translatable entity, to a translatable one, ideally there would need to be some way to select the language. Not sure about that, though. But we can definitely fix the case of joining two translatable entities as we can just make sure the langcodes match. (I guess that makes sense, but again, not really sure.)

User interface changes

?

API changes

?

Data model changes

?


Viewing all articles
Browse latest Browse all 294391

Trending Articles