You are here

public function RouteMethodSubscriber::onRouteBuilding in Drupal 9

Same name and namespace in other branches
  1. 8 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',
      ]);
    }
  }
}