You are here

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

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
commerce_promotion.route_subscriber in modules/promotion/commerce_promotion.services.yml
Drupal\commerce_promotion\EventSubscriber\RouteSubscriber

File

modules/promotion/src/EventSubscriber/RouteSubscriber.php, line 13

Namespace

Drupal\commerce_promotion\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase::getSubscribedEvents
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1