/**
  * Provides routes on route rebuild time.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function onDynamicRouteEvent(RouteBuildEvent $event)
 {
     $route_collection = $event->getRouteCollection();
     foreach ($this->entityManager->getDefinitions() as $entity_type) {
         if ($entity_type->hasRouteProviders()) {
             foreach ($this->entityManager->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.
                 $routes = $route_provider->getRoutes($entity_type);
                 if ($routes instanceof RouteCollection) {
                     $route_collection->addCollection($routes);
                 } elseif (is_array($routes)) {
                     foreach ($routes as $route_name => $route) {
                         $route_collection->add($route_name, $route);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getRouteProviders($entity_type)
 {
     return $this->entityManager->getRouteProviders($entity_type);
 }