Problem/Motivation
Term and other reference field's widget formatters don't use the translation of a referable entity, but just display the entity's default language label in any language.
Steps to reproduce on a fresh install of d8 8.0.x
- Enable the content_translation module
- Go to admin/config/regional/content-language and check the checkbox "Taxonomy Term", below check the checkbox of the Tags vocabulary
- Add an additional language @ /admin/config/regional/language
- Add some term to the tags vocabulary @ admin/structure/taxonomy/manage/tags/add in the default language, then translate that term
- Switch the display of the term reference field on the article content type to "Check boxes/radio buttons" @ admin/structure/types/manage/article/form-display
- Now open the article node form @ node/add/article in the default and in the additional language
Result: The term's checkbox is displayed in the default language only and the translation isn't displayed as checkbox label.
The same also applies when making content translatable, translating a node, adding a content reference field (with checkbox widget) to another content type and accessing that content type's node form.
Proposed resolution
Replace the $entity on which the label() method is invoked by $this->entityManager->getTranslationFromContext($entity)
Comments
Comment #2
s_leu commentedHere's a first patch that fixes the problem for Terms and all referable entities which use SelectionBase in their EntityReferenceSelection plugin and don't override getReferenceableEntities().
Comment #3
s_leu commentedGuess we also need tests for this.
Comment #4
s_leu commentedComment #5
berdirThere's an existing issue for autocomplete that also contains these changes, see #2144377: Entity reference autocomplete lists entity labels only in current content language.
We should consider separating that, that other issue might already have test coverage but was blocked on some query problem for a long time, then we can get this in already.
Comment #6
berdirComment #7
s_leu commentedComment #8
s_leu commentedObviously there were changes in SelectionBase since yesterday. Re-rolling.
Comment #9
berdirNeeds work for tests.
Comment #10
giancarlosotelo commentedRebased and added tests.
I am not sure if is the best place for the test but
TermTranslationBreadcrumbTestuseTaxonomyTranslationTestTraitwhich add some translations options.Comment #12
berdirTest looks pretty good to me, but it's part of a "TermTranslationBreadCrumbTest". What if we just rename the class to TermTranslationTest?
Comment #13
giancarlosotelo commentedOk, renamed.
Comment #14
berdirLooks good to me.
I think it would be nice to get this in, to remove this part of the problem from the more problematic issue #2144377: Entity reference autocomplete lists entity labels only in current content language.
Comment #17
ameymudras commentedModifying the patch as per the latest 8.0.x-dev version.
Comment #18
swentel commentedBack to RTBC
Comment #19
alexpottCommitted deaa762 and pushed to 8.0.x and 8.1.x. Thanks!