Problem/Motivation
On a multilingual system, when referencing and selecting an entity, the node edit form display shows this selected entity on its default language.
Steps to Reproduce
1. Create a "Node 1" in two languages, for example "NL" and "EN".
2. Create a "Node 2" in two languages, for example "NL" and "EN".
2. Edit "Node 1" and reference "Node 2" in both languages.
Expected Result on "Node 1" edit form set to "NL" language:

"Node 2" should show either the selected node language or the context language which, in this case, is NL.
Actual result on node "Node 1" edit form set to "NL" language:

"Node 2" shows the default language title, "EN".
Proposed solution
Update EntityBrowserElement where entity is loaded and add \Drupal::service('entity.repository')->getTranslationFromContext($entity);
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | Language matches context.mov | 1.9 MB | oknate |
| #5 | Language always default.mov | 2.29 MB | oknate |
| #2 | language_aware_entity_preview-3019943-2.patch | 690 bytes | rutiolma |
Comments
Comment #2
rutiolmaThis approach uses Entity Repository service to get the contextual language of the entity.
Besides the above mentioned issue, this should fix the entity display on other places since this function is called in other places.
This is in someway related with #2820478 and it seems the best approach considering that EB only gets entity_type:id, not the langcode.
Comment #3
oknateComment #4
oknateComment #5
oknateHere's a video example of the bug, I'm editing the French version of node 1, and whether I select the English or French, it always shows the English title.
Comment #6
oknateMarking RTBC. Here's a video example of the fix. It now shows the language from the context. In other words, if you're editing the French translation, it will show the French translation, if available.
Comment #9
oknateCommitted, thanks!