You are here

class RouteSubscriber in Commerce Shipping 8.2

Re-add the route requirement for the shipment collection route.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
commerce_shipping.services.yml in ./commerce_shipping.services.yml
commerce_shipping.services.yml
1 service uses RouteSubscriber
commerce_shipping.route_subscriber in ./commerce_shipping.services.yml
Drupal\commerce_shipping\EventSubscriber\RouteSubscriber

File

src/EventSubscriber/RouteSubscriber.php, line 12

Namespace

Drupal\commerce_shipping\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) {

    // ShipmentRouteProvider sets the "_shipment_collection_access" requirement
    // to the shipment collection route but it's being removed by the route
    // subscriber provided by Views, so put it back.
    // @todo: Remove once Views will merge the route requirements.
    $route = $collection
      ->get('entity.commerce_shipment.collection');
    if ($route) {
      $route
        ->setRequirement('_shipment_collection_access', 'TRUE');
    }
  }

}

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