You are here

protected function AdminRouteSubscriber::alterRoutes in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php \Drupal\system\EventSubscriber\AdminRouteSubscriber::alterRoutes()

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php, line 18

Class

AdminRouteSubscriber
Adds the _admin_route option to each admin HTML route.

Namespace

Drupal\system\EventSubscriber

Code

protected function alterRoutes(RouteCollection $collection) {
  foreach ($collection
    ->all() as $route) {
    $path = $route
      ->getPath();
    if (($path == '/admin' || strpos($path, '/admin/') === 0) && !$route
      ->hasOption('_admin_route') && static::isHtmlRoute($route)) {
      $route
        ->setOption('_admin_route', TRUE);
    }
  }
}