You are here

public function RoutingAlterSubscriber::onRoutingRouteAlter in Commerce Cart API 8

Alters our cart API routes to remove _csrf_request_header_token.

Parameters

\Drupal\Core\Routing\RouteBuildEvent $event: The event to process.

File

src/EventSubscriber/RoutingAlterSubscriber.php, line 20

Class

RoutingAlterSubscriber
Removes CSRF header requirements from our routes.

Namespace

Drupal\commerce_cart_api\EventSubscriber

Code

public function onRoutingRouteAlter(RouteBuildEvent $event) {
  $route_collection = $event
    ->getRouteCollection();
  foreach ($route_collection as $route) {
    if ($route
      ->hasRequirement('_cart_api')) {
      $requirements = $route
        ->getRequirements();
      unset($requirements['_csrf_request_header_token']);
      $route
        ->setRequirements($requirements);
    }
  }
}