comparison core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Core\EventSubscriber; 3 namespace Drupal\Core\EventSubscriber;
4 4
5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
5 use Drupal\Core\Entity\EntityManagerInterface; 6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Routing\RouteBuildEvent; 8 use Drupal\Core\Routing\RouteBuildEvent;
7 use Drupal\Core\Routing\RoutingEvents; 9 use Drupal\Core\Routing\RoutingEvents;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface; 10 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9 use Symfony\Component\Routing\RouteCollection; 11 use Symfony\Component\Routing\RouteCollection;
10 12
11 /** 13 /**
12 * Ensures that routes can be provided by entity types. 14 * Ensures that routes can be provided by entity types.
13 */ 15 */
14 class EntityRouteProviderSubscriber implements EventSubscriberInterface { 16 class EntityRouteProviderSubscriber implements EventSubscriberInterface {
17 use DeprecatedServicePropertyTrait;
15 18
16 /** 19 /**
17 * The entity manager. 20 * {@inheritdoc}
21 */
22 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
23
24 /**
25 * The entity type manager service.
18 * 26 *
19 * @var \Drupal\Core\Entity\EntityManagerInterface 27 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
20 */ 28 */
21 protected $entityManager; 29 protected $entityTypeManager;
22 30
23 /** 31 /**
24 * Constructs a new EntityRouteProviderSubscriber instance. 32 * Constructs a new EntityRouteProviderSubscriber instance.
25 * 33 *
26 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 34 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
27 * The entity manager. 35 * The entity type manager service.
28 */ 36 */
29 public function __construct(EntityManagerInterface $entity_manager) { 37 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
30 $this->entityManager = $entity_manager; 38 if ($entity_type_manager instanceof EntityManagerInterface) {
39 @trigger_error('Passing the entity.manager service to EntityRouteProviderSubscriber::__construct() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Pass the new dependencies instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
40 $this->entityTypeManager = \Drupal::entityTypeManager();
41 }
42 else {
43 $this->entityTypeManager = $entity_type_manager;
44 }
31 } 45 }
32 46
33 /** 47 /**
34 * Provides routes on route rebuild time. 48 * Provides routes on route rebuild time.
35 * 49 *
36 * @param \Drupal\Core\Routing\RouteBuildEvent $event 50 * @param \Drupal\Core\Routing\RouteBuildEvent $event
37 * The route build event. 51 * The route build event.
38 */ 52 */
39 public function onDynamicRouteEvent(RouteBuildEvent $event) { 53 public function onDynamicRouteEvent(RouteBuildEvent $event) {
40 $route_collection = $event->getRouteCollection(); 54 $route_collection = $event->getRouteCollection();
41 foreach ($this->entityManager->getDefinitions() as $entity_type) { 55 foreach ($this->entityTypeManager->getDefinitions() as $entity_type) {
42 if ($entity_type->hasRouteProviders()) { 56 if ($entity_type->hasRouteProviders()) {
43 foreach ($this->entityManager->getRouteProviders($entity_type->id()) as $route_provider) { 57 foreach ($this->entityTypeManager->getRouteProviders($entity_type->id()) as $route_provider) {
44 // Allow to both return an array of routes or a route collection, 58 // Allow to both return an array of routes or a route collection,
45 // like route_callbacks in the routing.yml file. 59 // like route_callbacks in the routing.yml file.
46 60
47 $routes = $route_provider->getRoutes($entity_type); 61 $routes = $route_provider->getRoutes($entity_type);
48 if ($routes instanceof RouteCollection) { 62 if ($routes instanceof RouteCollection) {