Skip to content
Snippets Groups Projects
Commit b2771c9f authored by artis.bajars's avatar artis.bajars
Browse files

Load term translations from context

parent ca33ec27
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ namespace Drupal\hierarchy_manager\Controller; ...@@ -4,6 +4,7 @@ namespace Drupal\hierarchy_manager\Controller;
use Drupal\Core\Access\CsrfTokenGenerator; use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Term;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -37,13 +38,21 @@ class HmTaxonomyController extends ControllerBase { ...@@ -37,13 +38,21 @@ class HmTaxonomyController extends ControllerBase {
*/ */
protected $hmPluginTypeManager; protected $hmPluginTypeManager;
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct(CsrfTokenGenerator $csrfToken, EntityTypeManagerInterface $entity_type_manager, $plugin_type_manager) { public function __construct(CsrfTokenGenerator $csrfToken, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, $plugin_type_manager) {
$this->csrfToken = $csrfToken; $this->csrfToken = $csrfToken;
$this->entityTypeManager = $entity_type_manager; $this->entityTypeManager = $entity_type_manager;
$this->entityRepository = $entity_repository;
$this->storageController = $entity_type_manager->getStorage('taxonomy_term'); $this->storageController = $entity_type_manager->getStorage('taxonomy_term');
$this->hmPluginTypeManager = $plugin_type_manager; $this->hmPluginTypeManager = $plugin_type_manager;
} }
...@@ -55,6 +64,7 @@ class HmTaxonomyController extends ControllerBase { ...@@ -55,6 +64,7 @@ class HmTaxonomyController extends ControllerBase {
return new static( return new static(
$container->get('csrf_token'), $container->get('csrf_token'),
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
$container->get('entity.repository'),
$container->get('hm.plugin_type_manager') $container->get('hm.plugin_type_manager')
); );
} }
...@@ -95,6 +105,7 @@ class HmTaxonomyController extends ControllerBase { ...@@ -95,6 +105,7 @@ class HmTaxonomyController extends ControllerBase {
foreach ($tree as $term) { foreach ($tree as $term) {
if ($term instanceof Term) { if ($term instanceof Term) {
$term = $this->entityRepository->getTranslationFromContext($term);
// User can only access the terms that they can update. // User can only access the terms that they can update.
if ($access_control_handler->access($term, 'update')) { if ($access_control_handler->access($term, 'update')) {
if (empty($destination)) { if (empty($destination)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment