function AdminRouteSubscriber::alterRoutes

Same name in other branches
  1. 9 core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php \Drupal\system\EventSubscriber\AdminRouteSubscriber::alterRoutes()
  2. 8.9.x core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php \Drupal\system\EventSubscriber\AdminRouteSubscriber::alterRoutes()
  3. 10 core/modules/system/src/EventSubscriber/AdminRouteSubscriber.php \Drupal\system\EventSubscriber\AdminRouteSubscriber::alterRoutes()

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' || str_starts_with($path, '/admin/')) && !$route->hasOption('_admin_route') && static::isHtmlRoute($route)) {
            $route->setOption('_admin_route', TRUE);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.