You are here

class RouteSubscriber in Commerce Invoice 8.2

Re-Add the route requirement for the order invoices route.

Hierarchy

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

Expanded class hierarchy of RouteSubscriber

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

File

src/EventSubscriber/RouteSubscriber.php, line 13

Namespace

Drupal\commerce_invoice\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_order.invoices');
    if ($route) {
      $route
        ->setRequirement('_invoice_order_access', 'TRUE');
      $route
        ->setDefault('commerce_invoice_type', 'default');
    }
    $route = $collection
      ->get('entity.commerce_order.invoice_add_form');
    if ($route) {
      $route
        ->setDefault('commerce_invoice_type', 'default');
    }
    $route = $collection
      ->get('entity.commerce_invoice.canonical');
    if ($route) {
      $route
        ->setDefault('_title_callback', InvoiceController::class . '::title');
    }
  }

}

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