Пример #1
0
 /**
  * Collects all REST end-points.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function onRouteAlter(RouteBuildEvent $event) {
   $collection = $event->getRouteCollection();
   foreach ($collection->all() as $route_name => $route) {
     // Rest module endpoint.
     if (strpos($route_name, 'rest.') === 0) {
       $this->restRouteNames[$route_name] = $route_name;
     }
     // Views module route.
     if (strpos($route_name, 'view.') === 0 && ($parts = explode('.', $route_name))
       && count($parts) == 3) {
       // We need to introspect the display type.
       list(, $view_id, $display_id) = $parts;
       $entity = $this->viewsStorage->load($view_id);
       if (empty($entity)) {
         // Non-existent view.
         continue;
       }
       // Build the view.
       if (empty($this->builtViews[$view_id])) {
         $this->builtViews[$view_id] = $this->executableFactory->get($entity);
         $view = $this->builtViews[$view_id];
       }
       else {
         $view = $this->builtViews[$view_id];
       }
       // Set the given display.
       $view->setDisplay($display_id);
       $display = $view->getDisplay();
       if ($display instanceof RestExport) {
         $this->restRouteNames[$route_name] = $route_name;
       }
     }
   }
 }
Пример #2
0
 /**
  * Collects all path roots.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function onRouteAlter(RouteBuildEvent $event)
 {
     $collection = $event->getRouteCollection();
     foreach ($collection->all() as $route) {
         $bits = explode('/', ltrim($route->getPath(), '/'));
         $this->pathRoots[$bits[0]] = $bits[0];
     }
 }
Пример #3
0
 /**
  * Alters the routes.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event to process.
  */
 public function alterRoutes(RouteBuildEvent $event) {
   if (\Drupal::config('ds_extras.settings')->get('override_node_revision')) {
     $route = $event->getRouteCollection()->get('entity.node.revision');
     if (!empty($route)) {
       $route->setDefault('_controller', '\Drupal\ds_extras\Controller\DsExtrasController::revisionShow');
     }
   }
 }
Пример #4
0
 /**
  * Adds a print route for each content entity.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function routes(RouteBuildEvent $event)
 {
     $collection = $event->getRouteCollection();
     foreach ($this->printableEntityManager->getPrintableEntities() as $entity_type => $entity_definition) {
         $route = new Route("/printable/{printable_format}/{$entity_type}/{entity}", array('_controller' => 'Drupal\\printable\\Controller\\PrintableController::showFormat', '_title' => 'Printable'), array('_permission' => 'view printer friendly versions'), array('parameters' => array('entity' => array('type' => 'entity:' . $entity_type))));
         $collection->add('printable.show_format.' . $entity_type, $route);
     }
 }
Пример #5
0
 /**
  * Sets a default value of GET|POST for the _method route property.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event containing the build routes.
  */
 public function onRouteBuilding(RouteBuildEvent $event)
 {
     foreach ($event->getRouteCollection() as $route) {
         $methods = $route->getMethods();
         if (empty($methods)) {
             $route->setMethods(array('GET', 'POST'));
         }
     }
 }
 /**
  * Alters select routes to have the '_no_big_pipe' option.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event to process.
  */
 public function onRoutingRouteAlterSetNoBigPipe(RouteBuildEvent $event)
 {
     $no_big_pipe_routes = ['system.batch_page.html', 'system.modules_list'];
     $route_collection = $event->getRouteCollection();
     foreach ($no_big_pipe_routes as $excluded_route) {
         if ($route = $route_collection->get($excluded_route)) {
             $route->setOption('_no_big_pipe', TRUE);
         }
     }
 }
Пример #7
0
 /**
  * Alters existing routes for a specific collection.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function onAlterRoutes(RouteBuildEvent $event)
 {
     $collection = $event->getRouteCollection();
     foreach ($collection->all() as $name => $route) {
         if (strpos($route->getPath(), '/admin/') !== 0 && $route->getPath() != '/admin') {
             $this->nonAdminRoutesOnRebuild[] = $name;
         }
     }
     $this->nonAdminRoutesOnRebuild = array_unique($this->nonAdminRoutesOnRebuild);
 }
 /**
  * Adds supported formats to the user authentication HTTP routes.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event to process.
  */
 public function onRoutingAlterAddFormats(RouteBuildEvent $event)
 {
     $route_names = ['user.login_status.http', 'user.login.http', 'user.logout.http'];
     $routes = $event->getRouteCollection();
     foreach ($route_names as $route_name) {
         if ($route = $routes->get($route_name)) {
             $formats = explode('|', $route->getRequirement('_format'));
             $formats = array_unique($formats + $this->serializerFormats);
             $route->setRequirement('_format', implode('|', $formats));
         }
     }
 }
 /**
  * Adds routes to enabled REST resources.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route building event.
  */
 public function dynamicRoutes(RouteBuildEvent $event)
 {
     $collection = $event->getRouteCollection();
     $enabled_resources = $this->config->get('rest.settings')->load()->get('resources');
     // Iterate over all enabled resource plugins.
     foreach ($enabled_resources as $id => $enabled_methods) {
         $plugin = $this->manager->getInstance(array('id' => $id));
         foreach ($plugin->routes() as $route) {
             $operation = $route->getRequirement('_operation');
             if ($operation) {
                 $collection->add("services.{$operation}", $route);
             }
         }
     }
 }
Пример #10
0
 /**
  * Alters existing routes.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route building event.
  */
 public function alterRoutes(RouteBuildEvent $event)
 {
     // Fetch the collection which can be altered.
     $collection = $event->getRouteCollection();
     // The event is fired multiple times so ensure that the user_page route
     // is available.
     if ($route = $collection->get('user.login')) {
         $route->setPath('/mylogin');
     }
     if ($route = $collection->get('user.logout')) {
         $route->setPath('/mylogout');
     }
     if ($route = $collection->get('view.frontpage.page_1')) {
         $route->setRequirement('_access', 'false');
     }
 }
 /**
  * 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);
                     }
                 }
             }
         }
     }
 }
 /**
  * Applies parameter converters to route parameters.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event to process.
  */
 public function onRoutingRouteAlterSetParameterConverters(RouteBuildEvent $event)
 {
     $this->paramConverterManager->setRouteParameterConverters($event->getRouteCollection());
 }
 /**
  * Applies parameter converters to route parameters.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event to process.
  */
 public function onRoutingRouteAlterSetType(RouteBuildEvent $event)
 {
     foreach ($event->getRouteCollection() as $route) {
         $this->resolverManager->setRouteOptions($route);
     }
 }
Пример #14
0
 /**
  * Adds the route_enhancer object to the route collection.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function onRouteAlter(RouteBuildEvent $event)
 {
     $this->routeEnhancer->setEnhancers($event->getRouteCollection());
 }
 /**
  * Delegates the route altering to self::alterRoutes().
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function onAlterRoutes(RouteBuildEvent $event)
 {
     $collection = $event->getRouteCollection();
     $this->alterRoutes($collection);
 }
Пример #16
0
 /**
  * Apply access checks to routes.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The event to process.
  */
 public function onRoutingRouteAlterSetAccessCheck(RouteBuildEvent $event)
 {
     $this->accessManager->setChecks($event->getRouteCollection());
 }