class RouteSubscriber in Commerce Core 8.2
Provides a route subscriber that adding the _admin_route option to the routes like "promotion/%/coupons".
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\commerce_promotion\EventSubscriber\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
- commerce_promotion.services.yml in modules/
promotion/ commerce_promotion.services.yml - modules/promotion/commerce_promotion.services.yml
1 service uses RouteSubscriber
File
- modules/
promotion/ src/ EventSubscriber/ RouteSubscriber.php, line 13
Namespace
Drupal\commerce_promotion\EventSubscriberView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
// Ensure to run after the Views route subscriber.
// @see \Drupal\views\EventSubscriber\RouteSubscriber.
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-200,
];
return $events;
}
/**
* {@inheritdoc}
*/
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',
],
]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public static | function |
Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase:: |
|
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |