Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->entityStorage->loadMultiple() as $entity_id => $entity) {
         /** @var $entity \Drupal\page_manager\PageInterface */
         // If the page is disabled skip making a route for it.
         if (!$entity->status() || $entity->isFallbackPage()) {
             continue;
         }
         // Prepare a route name to use if this is a custom page.
         $route_name = "page_manager.page_view_{$entity_id}";
         // Prepare the values that need to be altered for an existing page.
         $path = $entity->getPath();
         $parameters = ['page_manager_page' => ['type' => 'entity:page']];
         // Loop through all existing routes to see if this is overriding a route.
         foreach ($collection->all() as $name => $collection_route) {
             // Find all paths which match the path of the current display.
             $route_path = RouteCompiler::getPathWithoutDefaults($collection_route);
             $route_path = RouteCompiler::getPatternOutline($route_path);
             if ($path == $route_path) {
                 // Adjust the path to translate %placeholders to {slugs}.
                 $path = $collection_route->getPath();
                 // Merge in any route parameter definitions.
                 $parameters += $collection_route->getOption('parameters') ?: [];
                 // Update the route name this will be added to.
                 $route_name = $name;
                 // Remove the existing route.
                 $collection->remove($route_name);
                 break;
             }
         }
         // Construct an add a new route.
         $route = new Route($path, ['_entity_view' => 'page_manager_page', 'page_manager_page' => $entity_id, '_title' => $entity->label()], ['_entity_access' => 'page_manager_page.view'], ['parameters' => $parameters, '_admin_route' => $entity->usesAdminTheme()]);
         $collection->add($route_name, $route);
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getRoutesByPattern($pattern)
 {
     $path = RouteCompiler::getPatternOutline($pattern);
     return $this->getRoutesByPath($path);
 }
 /**
  * {@inheritdoc}
  */
 public function getRoutesByPattern($pattern)
 {
     $path = RouteCompiler::getPatternOutline($pattern);
     $this->routeBuilder->rebuildIfNeeded();
     return $this->getRoutesByPath($path);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     $view_route_names = array();
     $view_path = $this->getPath();
     foreach ($collection->all() as $name => $route) {
         // Find all paths which match the path of the current display..
         $route_path = RouteCompiler::getPathWithoutDefaults($route);
         $route_path = RouteCompiler::getPatternOutline($route_path);
         // Ensure that we don't override a route which is already controlled by
         // views.
         if (!$route->hasDefault('view_id') && '/' . $view_path == $route_path) {
             $parameters = $route->compile()->getPathVariables();
             // @todo Figure out whether we need to merge some settings (like
             // requirements).
             // Replace the existing route with a new one based on views.
             $original_route = $collection->get($name);
             $collection->remove($name);
             $view_id = $this->view->storage->id();
             $display_id = $this->display['id'];
             $route = $this->getRoute($view_id, $display_id);
             $path = $route->getPath();
             // Replace the path with the original parameter names and add a mapping.
             $argument_map = array();
             // We assume that the numeric ids of the parameters match the one from
             // the view argument handlers.
             foreach ($parameters as $position => $parameter_name) {
                 $path = str_replace('{arg_' . $position . '}', '{' . $parameter_name . '}', $path);
                 $argument_map['arg_' . $position] = $parameter_name;
             }
             // Copy the original options from the route, so for example we ensure
             // that parameter conversion options is carried over.
             $route->setOptions($route->getOptions() + $original_route->getOptions());
             // Set the corrected path and the mapping to the route object.
             $route->setOption('_view_argument_map', $argument_map);
             $route->setPath($path);
             $collection->add($name, $route);
             $view_route_names[$view_id . '.' . $display_id] = $name;
         }
     }
     return $view_route_names;
 }
 /**
  * Finds the overridden route name.
  *
  * @param \Drupal\page_manager\PageInterface $entity
  *   The page entity.
  * @param \Symfony\Component\Routing\RouteCollection $collection
  *   The route collection.
  *
  * @return string|null
  *   Either the route name if this is overriding an existing path, or NULL.
  */
 protected function findPageRouteName(PageInterface $entity, RouteCollection $collection)
 {
     // Get the stored page path.
     $path = $entity->getPath();
     // Loop through all existing routes to see if this is overriding a route.
     foreach ($collection->all() as $name => $collection_route) {
         // Find all paths which match the path of the current display.
         $route_path = $collection_route->getPath();
         $route_path_outline = RouteCompiler::getPatternOutline($route_path);
         // Match either the path or the outline, e.g., '/foo/{foo}' or '/foo/%'.
         if ($path === $route_path || $path === $route_path_outline) {
             // Return the overridden route name.
             return $name;
         }
     }
 }