RouteSubscriber.php in Commerce Core 8.2
File
modules/promotion/src/EventSubscriber/RouteSubscriber.php
View source
<?php
namespace Drupal\commerce_promotion\EventSubscriber;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-200,
];
return $events;
}
protected function alterRoutes(RouteCollection $collection) {
$route = $collection
->get('entity.commerce_promotion_coupon.collection');
if ($route) {
$route
->setOption('_admin_route', TRUE);
$route
->setOption('parameters', [
'commerce_promotion' => [
'type' => 'entity:commerce_promotion',
],
]);
}
}
}
Classes
Name |
Description |
RouteSubscriber |
Provides a route subscriber that adding the _admin_route option
to the routes like "promotion/%/coupons". |