all() as $name => $route) { if ($not_allowed_variables = array_intersect($route->compile()->getVariables(), $special_variables)) { $reserved = implode(', ', $not_allowed_variables); throw new \InvalidArgumentException(sprintf('Route %s uses reserved variable names: %s', $name, $reserved)); } } } /** * Delegates the route altering to self::alterRoutes(). * * @param \Drupal\Core\Routing\RouteBuildEvent $event * The route build event. */ public function onAlterRoutes(RouteBuildEvent $event) { $collection = $event->getRouteCollection(); $this->alterRoutes($collection); } }