Chris@0: 'entity.manager']; Chris@18: Chris@18: /** Chris@18: * The entity type manager service. Chris@0: * Chris@18: * @var \Drupal\Core\Entity\EntityTypeManagerInterface Chris@0: */ Chris@18: protected $entityTypeManager; Chris@0: Chris@0: /** Chris@0: * Constructs a new EntityRouteProviderSubscriber instance. Chris@0: * Chris@18: * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager Chris@18: * The entity type manager service. Chris@0: */ Chris@18: public function __construct(EntityTypeManagerInterface $entity_type_manager) { Chris@18: if ($entity_type_manager instanceof EntityManagerInterface) { Chris@18: @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); Chris@18: $this->entityTypeManager = \Drupal::entityTypeManager(); Chris@18: } Chris@18: else { Chris@18: $this->entityTypeManager = $entity_type_manager; Chris@18: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides routes on route rebuild time. Chris@0: * Chris@0: * @param \Drupal\Core\Routing\RouteBuildEvent $event Chris@0: * The route build event. Chris@0: */ Chris@0: public function onDynamicRouteEvent(RouteBuildEvent $event) { Chris@0: $route_collection = $event->getRouteCollection(); Chris@18: foreach ($this->entityTypeManager->getDefinitions() as $entity_type) { Chris@0: if ($entity_type->hasRouteProviders()) { Chris@18: foreach ($this->entityTypeManager->getRouteProviders($entity_type->id()) as $route_provider) { Chris@0: // Allow to both return an array of routes or a route collection, Chris@0: // like route_callbacks in the routing.yml file. Chris@0: Chris@0: $routes = $route_provider->getRoutes($entity_type); Chris@0: if ($routes instanceof RouteCollection) { Chris@0: $routes = $routes->all(); Chris@0: } Chris@0: foreach ($routes as $route_name => $route) { Chris@0: // Don't override existing routes. Chris@0: if (!$route_collection->get($route_name)) { Chris@0: $route_collection->add($route_name, $route); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: $events[RoutingEvents::DYNAMIC][] = ['onDynamicRouteEvent']; Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }