function RouteMethodSubscriber::onRouteBuilding
Sets a default value of GET|POST for the _method route property.
Parameters
\Drupal\Core\Routing\RouteBuildEvent $event: The event containing the build routes.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ RouteMethodSubscriber.php, line 26
Class
- RouteMethodSubscriber
- Provides a default value for the HTTP method restriction on routes.
Namespace
Drupal\Core\EventSubscriberCode
public function onRouteBuilding(RouteBuildEvent $event) {
foreach ($event->getRouteCollection() as $route) {
$methods = $route->getMethods();
if (empty($methods)) {
$route->setMethods([
'GET',
'POST',
]);
}
}
}