From 4aac6a334fca2ab9f39a3f4c8ff5d07347359cc9 Mon Sep 17 00:00:00 2001 From: William Hearn Date: Thu, 14 Dec 2017 12:46:34 -0500 Subject: [PATCH] Issue #2765297 by sylus, heikki, googletorp, dnotes: Return translated term name on views "Content: Has taxonomy term ID (with depth)" --- .../taxonomy/src/Plugin/views/argument/Taxonomy.php | 14 +++++++++++--- core/modules/taxonomy/taxonomy.tokens.inc | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/modules/taxonomy/src/Plugin/views/argument/Taxonomy.php b/core/modules/taxonomy/src/Plugin/views/argument/Taxonomy.php index 25efbf3..71b211f 100644 --- a/core/modules/taxonomy/src/Plugin/views/argument/Taxonomy.php +++ b/core/modules/taxonomy/src/Plugin/views/argument/Taxonomy.php @@ -2,6 +2,7 @@ namespace Drupal\taxonomy\Plugin\views\argument; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\views\Plugin\views\argument\NumericArgument; @@ -17,6 +18,11 @@ class Taxonomy extends NumericArgument implements ContainerFactoryPluginInterface { /** + * @var EntityRepositoryInterface + */ + protected $entityRepository; + + /** * @var EntityStorageInterface */ protected $termStorage; @@ -24,9 +30,10 @@ class Taxonomy extends NumericArgument implements ContainerFactoryPluginInterfac /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $term_storage) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $term_storage, EntityRepositoryInterface $entityRepository) { parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->entityRepository = $entityRepository; $this->termStorage = $term_storage; } @@ -38,7 +45,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager')->getStorage('taxonomy_term') + $container->get('entity.manager')->getStorage('taxonomy_term'), + $container->get('entity.repository') ); } @@ -50,7 +58,7 @@ public function title() { if ($this->argument) { $term = $this->termStorage->load($this->argument); if (!empty($term)) { - return $term->getName(); + return $this->entityRepository->getTranslationFromContext($term)->label(); } } // TODO review text diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index 211a121..764fd04 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -98,6 +98,7 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable $taxonomy_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); if ($type == 'term' && !empty($data['term'])) { $term = $data['term']; + $term = \Drupal::entityManager()->getTranslationFromContext($term); foreach ($tokens as $name => $original) { switch ($name) { @@ -106,7 +107,7 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable break; case 'name': - $replacements[$original] = $term->getName(); + $replacements[$original] = $term->label(); break; case 'description': -- 2.5.4 (Apple Git-61)