function RouteMethodSubscriber::onRouteBuilding

Same name in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/RouteMethodSubscriber.php \Drupal\Core\EventSubscriber\RouteMethodSubscriber::onRouteBuilding()
  2. 8.9.x core/lib/Drupal/Core/EventSubscriber/RouteMethodSubscriber.php \Drupal\Core\EventSubscriber\RouteMethodSubscriber::onRouteBuilding()
  3. 10 core/lib/Drupal/Core/EventSubscriber/RouteMethodSubscriber.php \Drupal\Core\EventSubscriber\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\EventSubscriber

Code

public function onRouteBuilding(RouteBuildEvent $event) {
    foreach ($event->getRouteCollection() as $route) {
        $methods = $route->getMethods();
        if (empty($methods)) {
            $route->setMethods([
                'GET',
                'POST',
            ]);
        }
    }
}

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