You are here

protected function PageManagerRoutes::findOverriddenRouteName in Page Manager 8

Same name and namespace in other branches
  1. 8.4 src/Routing/PageManagerRoutes.php \Drupal\page_manager\Routing\PageManagerRoutes::findOverriddenRouteName()

Finds the overridden route name.

Parameters

\Drupal\page_manager\PageInterface $entity: The page entity.

\Symfony\Component\Routing\RouteCollection $collection: The route collection.

Return value

string|null Either the route name if this is overriding an existing path, or NULL.

1 call to PageManagerRoutes::findOverriddenRouteName()
PageManagerRoutes::alterRoutes in src/Routing/PageManagerRoutes.php
Alters existing routes for a specific collection.

File

src/Routing/PageManagerRoutes.php, line 136
Contains \Drupal\page_manager\Routing\PageManagerRoutes.

Class

PageManagerRoutes
Provides routes for page entities.

Namespace

Drupal\page_manager\Routing

Code

protected function findOverriddenRouteName(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/%'.
    // The route must be a GET route and must not specify a format.
    if (($path === $route_path || $path === $route_path_outline) && (!$collection_route
      ->getMethods() || in_array('GET', $collection_route
      ->getMethods())) && !$collection_route
      ->hasRequirement('_format')) {

      // Return the overridden route name.
      return $name;
    }
  }
}