function SpecialAttributesRouteSubscriber::alterRoutes

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber::alterRoutes()
  2. 10 core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber::alterRoutes()
  3. 11.x core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber::alterRoutes()

Overrides RouteSubscriberBase::alterRoutes

1 call to SpecialAttributesRouteSubscriber::alterRoutes()
SpecialAttributesRouteSubscriber::onAlterRoutes in core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php
Delegates the route altering to self::alterRoutes().

File

core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php, line 18

Class

SpecialAttributesRouteSubscriber
Provides a route subscriber which checks for invalid pattern variables.

Namespace

Drupal\Core\EventSubscriber

Code

protected function alterRoutes(RouteCollection $collection) {
    $special_variables = [
        'system_path',
        '_legacy',
        '_raw_variables',
        RouteObjectInterface::ROUTE_OBJECT,
        RouteObjectInterface::ROUTE_NAME,
        '_content',
        '_controller',
        '_form',
    ];
    foreach ($collection->all() as $name => $route) {
        if ($not_allowed_variables = array_intersect($route->compile()
            ->getVariables(), $special_variables)) {
            $reserved = implode(', ', $not_allowed_variables);
            trigger_error(sprintf('Route %s uses reserved variable names: %s', $name, $reserved), E_USER_WARNING);
        }
    }
}

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