Mercurial > hg > cmmr2012-drupal-site
diff 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 |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php Thu May 09 15:34:47 2019 +0100 @@ -2,7 +2,9 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RoutingEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -12,22 +14,34 @@ * Ensures that routes can be provided by entity types. */ class EntityRouteProviderSubscriber implements EventSubscriberInterface { + use DeprecatedServicePropertyTrait; /** - * The entity manager. + * {@inheritdoc} + */ + protected $deprecatedProperties = ['entityManager' => 'entity.manager']; + + /** + * The entity type manager service. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * Constructs a new EntityRouteProviderSubscriber instance. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager service. */ - public function __construct(EntityManagerInterface $entity_manager) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_type_manager) { + if ($entity_type_manager instanceof EntityManagerInterface) { + @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); + $this->entityTypeManager = \Drupal::entityTypeManager(); + } + else { + $this->entityTypeManager = $entity_type_manager; + } } /** @@ -38,9 +52,9 @@ */ public function onDynamicRouteEvent(RouteBuildEvent $event) { $route_collection = $event->getRouteCollection(); - foreach ($this->entityManager->getDefinitions() as $entity_type) { + foreach ($this->entityTypeManager->getDefinitions() as $entity_type) { if ($entity_type->hasRouteProviders()) { - foreach ($this->entityManager->getRouteProviders($entity_type->id()) as $route_provider) { + foreach ($this->entityTypeManager->getRouteProviders($entity_type->id()) as $route_provider) { // Allow to both return an array of routes or a route collection, // like route_callbacks in the routing.yml file.