class RoutingAlterSubscriber in Commerce Cart API 8
Removes CSRF header requirements from our routes.
Hierarchy
- class \Drupal\commerce_cart_api\EventSubscriber\RoutingAlterSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RoutingAlterSubscriber
1 string reference to 'RoutingAlterSubscriber'
1 service uses RoutingAlterSubscriber
File
- src/
EventSubscriber/ RoutingAlterSubscriber.php, line 12
Namespace
Drupal\commerce_cart_api\EventSubscriberView source
class RoutingAlterSubscriber implements EventSubscriberInterface {
/**
* Alters our cart API routes to remove _csrf_request_header_token.
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The event to process.
*/
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);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[RoutingEvents::ALTER][] = [
'onRoutingRouteAlter',
-100,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RoutingAlterSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RoutingAlterSubscriber:: |
public | function | Alters our cart API routes to remove _csrf_request_header_token. |