class SpecialAttributesRouteSubscriber
Same name in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
- 8.9.x core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
- 10 core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
Provides a route subscriber which checks for invalid pattern variables.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber extends \Drupal\Core\Routing\RouteSubscriberBase
Expanded class hierarchy of SpecialAttributesRouteSubscriber
1 file declares its use of SpecialAttributesRouteSubscriber
- SpecialAttributesRouteSubscriberTest.php in core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ SpecialAttributesRouteSubscriberTest.php
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ SpecialAttributesRouteSubscriber.php, line 13
Namespace
Drupal\Core\EventSubscriberView source
class SpecialAttributesRouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
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);
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);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
RouteSubscriberBase::getSubscribedEvents | public static | function | 9 | ||
SpecialAttributesRouteSubscriber::alterRoutes | protected | function | Alters existing routes for a specific collection. | Overrides RouteSubscriberBase::alterRoutes | |
SpecialAttributesRouteSubscriber::onAlterRoutes | public | function | Delegates the route altering to self::alterRoutes(). | Overrides RouteSubscriberBase::onAlterRoutes |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.