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

  1. Enable the content_translation module
  2. Go to admin/config/regional/content-language and check the checkbox "Taxonomy Term", below check the checkbox of the Tags vocabulary
  3. Add an additional language @ /admin/config/regional/language
  4. Add some term to the tags vocabulary @ admin/structure/taxonomy/manage/tags/add in the default language, then translate that term
  5. 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
  6. 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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

s_leu created an issue. See original summary.

s_leu’s picture

Status: Active » Needs review
FileSize
1.79 KB

Here'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().

s_leu’s picture

Issue tags: +Needs tests

Guess we also need tests for this.

s_leu’s picture

Title: Entity reference formatter doesn't display term translations » Entity reference widget formatter doesn't display entity translations
Berdir’s picture

There'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.

Berdir’s picture

Title: Entity reference widget formatter doesn't display entity translations » Entity reference widgets doesn't display entity translations
s_leu’s picture

Title: Entity reference widgets doesn't display entity translations » Entity reference widgets don't display entity translations
s_leu’s picture

Obviously there were changes in SelectionBase since yesterday. Re-rolling.

Berdir’s picture

Status: Needs review » Needs work

Needs work for tests.

giancarlosotelo’s picture

Rebased and added tests.

I am not sure if is the best place for the test but TermTranslationBreadcrumbTest use TaxonomyTranslationTestTrait which add some translations options.

The last submitted patch, 10: entity-reference-widget-translation-2580423-10ONLYTEST.patch, failed testing.

Berdir’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
+++ b/core/modules/taxonomy/src/Tests/TermTranslationBreadcrumbTest.php
@@ -86,6 +86,34 @@ public function testTranslatedBreadcrumbs() {
+  /**
+   * Test translation of terms are showed in the node.
+   */
+  protected function testTermsTranslation() {

Test looks pretty good to me, but it's part of a "TermTranslationBreadCrumbTest". What if we just rename the class to TermTranslationTest?

giancarlosotelo’s picture

Status: Needs work » Needs review
FileSize
3.88 KB

Ok, renamed.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks 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.

The last submitted patch, 10: entity-reference-widget-translation-2580423-10ONLYTEST.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: entity-reference-widget-translation-2580423-13.patch, failed testing.

ameymudras’s picture

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed deaa762 and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed 425d682 on 8.1.x
    Issue #2580423 by giancarlosotelo, s_leu, ameymudras, Berdir: Entity...

  • alexpott committed deaa762 on
    Issue #2580423 by giancarlosotelo, s_leu, ameymudras, Berdir: Entity...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.