Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/src/TermBreadcrumbBuilder.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
2 | 2 |
3 namespace Drupal\taxonomy; | 3 namespace Drupal\taxonomy; |
4 | 4 |
5 use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; | 5 use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; |
6 use Drupal\Core\Breadcrumb\Breadcrumb; | 6 use Drupal\Core\Breadcrumb\Breadcrumb; |
7 use Drupal\Core\Entity\EntityManagerInterface; | 7 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; |
8 use Drupal\Core\Entity\EntityRepositoryInterface; | |
9 use Drupal\Core\Entity\EntityTypeManagerInterface; | |
8 use Drupal\Core\Link; | 10 use Drupal\Core\Link; |
9 use Drupal\Core\Routing\RouteMatchInterface; | 11 use Drupal\Core\Routing\RouteMatchInterface; |
10 use Drupal\Core\StringTranslation\StringTranslationTrait; | 12 use Drupal\Core\StringTranslation\StringTranslationTrait; |
11 | 13 |
12 /** | 14 /** |
13 * Provides a custom taxonomy breadcrumb builder that uses the term hierarchy. | 15 * Provides a custom taxonomy breadcrumb builder that uses the term hierarchy. |
14 */ | 16 */ |
15 class TermBreadcrumbBuilder implements BreadcrumbBuilderInterface { | 17 class TermBreadcrumbBuilder implements BreadcrumbBuilderInterface { |
16 use StringTranslationTrait; | 18 use StringTranslationTrait; |
19 use DeprecatedServicePropertyTrait; | |
17 | 20 |
18 /** | 21 /** |
19 * The entity manager. | 22 * {@inheritdoc} |
23 */ | |
24 protected $deprecatedProperties = ['entityManager' => 'entity.manager']; | |
25 | |
26 /** | |
27 * The entity repository manager. | |
20 * | 28 * |
21 * @var \Drupal\Core\Entity\EntityManagerInterface | 29 * @var \Drupal\Core\Entity\EntityRepositoryInterface |
22 */ | 30 */ |
23 protected $entityManager; | 31 protected $entityRepository; |
32 | |
33 /** | |
34 * The entity type manager. | |
35 * | |
36 * @var \Drupal\Core\Entity\EntityTypeManagerInterface | |
37 */ | |
38 protected $entityTypeManager; | |
24 | 39 |
25 /** | 40 /** |
26 * The taxonomy storage. | 41 * The taxonomy storage. |
27 * | 42 * |
28 * @var \Drupal\Taxonomy\TermStorageInterface | 43 * @var \Drupal\Taxonomy\TermStorageInterface |
30 protected $termStorage; | 45 protected $termStorage; |
31 | 46 |
32 /** | 47 /** |
33 * Constructs the TermBreadcrumbBuilder. | 48 * Constructs the TermBreadcrumbBuilder. |
34 * | 49 * |
35 * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager | 50 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
36 * The entity manager. | 51 * The entity type manager. |
52 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository | |
53 * The entity repository. | |
37 */ | 54 */ |
38 public function __construct(EntityManagerInterface $entityManager) { | 55 public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository = NULL) { |
39 $this->entityManager = $entityManager; | 56 $this->entityTypeManager = $entity_type_manager; |
40 $this->termStorage = $entityManager->getStorage('taxonomy_term'); | 57 $this->termStorage = $entity_type_manager->getStorage('taxonomy_term'); |
58 if (!$entity_repository) { | |
59 @trigger_error('The entity.repository service must be passed to TermBreadcrumbBuilder::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); | |
60 $entity_repository = \Drupal::service('entity.repository'); | |
61 } | |
62 $this->entityRepository = $entity_repository; | |
41 } | 63 } |
42 | 64 |
43 /** | 65 /** |
44 * {@inheritdoc} | 66 * {@inheritdoc} |
45 */ | 67 */ |
64 // vocabulary or term. | 86 // vocabulary or term. |
65 $parents = $this->termStorage->loadAllParents($term->id()); | 87 $parents = $this->termStorage->loadAllParents($term->id()); |
66 // Remove current term being accessed. | 88 // Remove current term being accessed. |
67 array_shift($parents); | 89 array_shift($parents); |
68 foreach (array_reverse($parents) as $term) { | 90 foreach (array_reverse($parents) as $term) { |
69 $term = $this->entityManager->getTranslationFromContext($term); | 91 $term = $this->entityRepository->getTranslationFromContext($term); |
70 $breadcrumb->addCacheableDependency($term); | 92 $breadcrumb->addCacheableDependency($term); |
71 $breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()])); | 93 $breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()])); |
72 } | 94 } |
73 | 95 |
74 // This breadcrumb builder is based on a route parameter, and hence it | 96 // This breadcrumb builder is based on a route parameter, and hence it |