diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index b5014bbe796e085ab5fac4c626851cb473be1ca4..0ccb24b49b9845635529b13c1b9cbf09f30ab431 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -21,6 +21,13 @@ class OverviewTerms extends FormBase { */ protected $moduleHandler; + /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + /** * The term storage handler. * @@ -38,6 +45,7 @@ class OverviewTerms extends FormBase { */ public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) { $this->moduleHandler = $module_handler; + $this->entityManager = $entity_manager; $this->storageController = $entity_manager->getStorage('taxonomy_term'); } @@ -209,6 +217,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular ]; foreach ($current_page as $key => $term) { /** @var $term \Drupal\Core\Entity\EntityInterface */ + $term = $this->entityManager->getTranslationFromContext($term); $form['terms'][$key]['#term'] = $term; $indentation = []; if (isset($term->depth) && $term->depth > 0) { diff --git a/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php b/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php index fb000e99c6a96cde12b71c7f1515b29ea2c9a57a..f60e77e534a644d5ae1975d73b648511aec225e7 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php @@ -107,4 +107,37 @@ public function testDefaultTermLanguage() { $this->assertOptionSelected('edit-langcode-0-value', 'cc', "The expected langcode, 'cc', was selected."); } + /** + * Tests that translated terms are displayed correctly on the term overview. + */ + public function testTermTranslatedOnOverviewPage() { + // Configure the vocabulary to not hide the language selector. + $edit = [ + 'default_language[language_alterable]' => TRUE, + ]; + $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); + + // Add a term. + $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); + // Submit the term. + $edit = [ + 'name[0][value]' => $this->randomMachineName(), + 'langcode[0][value]' => 'aa', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']); + $term = reset($terms); + + // Add a translation for that term. + $translated_title = $this->randomMachineName(); + $term->addTranslation('bb', [ + 'name' => $translated_title, + ]); + $term->save(); + + // Overview page in the other language shows the translated term + $this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); + $this->assertPattern('|]*>' . $translated_title . '|', 'The term language is correct'); + } + }