You are here

public function RouteMethodSubscriber::onRouteBuilding in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 31
Contains \Drupal\Core\EventSubscriber\RouteMethodSubscriber.

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(array(
        'GET',
        'POST',
      ));
    }
  }
}