summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-01-04 14:06:48 (GMT)
committerAlex Pott2016-01-04 14:06:48 (GMT)
commit425d682aa6a6b97e42f15813885ad0603b018a37 (patch)
tree83a8f499191ae29899f34857dafdb1687cd8de34
parentcba756ad4dc07f0821163ab81f1aa677505c4ae6 (diff)
Issue #2580423 by giancarlosotelo, s_leu, ameymudras, Berdir: Entity reference widgets don't display entity translations
-rw-r--r--core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php2
-rw-r--r--core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php2
-rw-r--r--core/modules/taxonomy/src/Tests/TermTranslationTest.php (renamed from core/modules/taxonomy/src/Tests/TermTranslationBreadcrumbTest.php)32
3 files changed, 32 insertions, 4 deletions
diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php
index 63f8c69..b108bb4 100644
--- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php
+++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php
@@ -257,7 +257,7 @@ class DefaultSelection extends PluginBase implements SelectionInterface, Selecti
$entities = $this->entityManager->getStorage($target_type)->loadMultiple($result);
foreach ($entities as $entity_id => $entity) {
$bundle = $entity->bundle();
- $options[$bundle][$entity_id] = Html::escape($entity->label());
+ $options[$bundle][$entity_id] = Html::escape($this->entityManager->getTranslationFromContext($entity)->label());
}
return $options;
diff --git a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
index 9420d95..995a6f6 100644
--- a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
+++ b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
@@ -73,7 +73,7 @@ class TermSelection extends DefaultSelection {
if ($vocabulary = Vocabulary::load($bundle)) {
if ($terms = $this->entityManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), 0, NULL, TRUE)) {
foreach ($terms as $term) {
- $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . Html::escape($term->getName());
+ $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . Html::escape($this->entityManager->getTranslationFromContext($term)->label());
}
}
}
diff --git a/core/modules/taxonomy/src/Tests/TermTranslationBreadcrumbTest.php b/core/modules/taxonomy/src/Tests/TermTranslationTest.php
index 0da6816..13b9577 100644
--- a/core/modules/taxonomy/src/Tests/TermTranslationBreadcrumbTest.php
+++ b/core/modules/taxonomy/src/Tests/TermTranslationTest.php
@@ -2,7 +2,7 @@
/**
* @file
- * Contains \Drupal\taxonomy\Tests\TermTranslationBreadcrumbTest.
+ * Contains \Drupal\taxonomy\Tests\TermTranslationTest.
*/
namespace Drupal\taxonomy\Tests;
@@ -15,7 +15,7 @@ use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;
*
* @group taxonomy
*/
-class TermTranslationBreadcrumbTest extends TaxonomyTestBase {
+class TermTranslationTest extends TaxonomyTestBase {
use AssertBreadcrumbTrait;
use TaxonomyTranslationTestTrait;
@@ -86,6 +86,34 @@ class TermTranslationBreadcrumbTest extends TaxonomyTestBase {
$term = $this->getLeafTerm();
$translated = $term->getTranslation($this->translateToLangcode);
$this->assertBreadcrumb($translated->urlInfo('canonical', ['language' => $languages[$this->translateToLangcode]]), $breadcrumb, $translated->label());
+
+ }
+
+ /**
+ * Test translation of terms are showed in the node.
+ */
+ protected function testTermsTranslation() {
+
+ // Set the display of the term reference field on the article content type
+ // to "Check boxes/radio buttons".
+ entity_get_form_display('node', 'article', 'default')
+ ->setComponent($this->termFieldName, array(
+ 'type' => 'options_buttons',
+ ))
+ ->save();
+ $this->drupalLogin($this->drupalCreateUser(['create article content']));
+
+ // Test terms are listed.
+ $this->drupalget('node/add/article');
+ $this->assertText('one');
+ $this->assertText('two');
+ $this->assertText('three');
+
+ // Test terms translated are listed.
+ $this->drupalget('hu/node/add/article');
+ $this->assertText('translatedOne');
+ $this->assertText('translatedTwo');
+ $this->assertText('translatedThree');
}
/**