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)
Comment | File | Size | Author |
---|---|---|---|
#17 | 2580423-17.patch | 3.91 KB | ameymudras |
Comments
Comment #2
s_leu CreditAttribution: s_leu at MD Systems GmbH 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 CreditAttribution: s_leu at MD Systems GmbH commentedGuess we also need tests for this.
Comment #4
s_leu CreditAttribution: s_leu at MD Systems GmbH 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 CreditAttribution: s_leu at MD Systems GmbH commentedComment #8
s_leu CreditAttribution: s_leu at MD Systems GmbH commentedObviously there were changes in SelectionBase since yesterday. Re-rolling.
Comment #9
BerdirNeeds work for tests.
Comment #10
giancarlosotelo CreditAttribution: giancarlosotelo at MD Systems GmbH commentedRebased and added tests.
I am not sure if is the best place for the test but
TermTranslationBreadcrumbTest
useTaxonomyTranslationTestTrait
which 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 CreditAttribution: giancarlosotelo at MD Systems GmbH 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 CreditAttribution: ameymudras as a volunteer commentedModifying the patch as per the latest 8.0.x-dev version.
Comment #18
swentel CreditAttribution: swentel commentedBack to RTBC
Comment #19
alexpottCommitted deaa762 and pushed to 8.0.x and 8.1.x. Thanks!