You are here

class RouteSubscriber in Taxonomy Views Integrator 8

Alters the route for using Taxonomy Views Integrator.

Views is allowed to alter and builds the routes first, and we then alter this route after the fact. The idea is so we can have multiple views that define `taxonomy/term/%` as the page path, and the settings form on the term/vocab let the user determine which view displays.

Otherwise, Views will always control the path, and that's not what we want.

Hierarchy

Expanded class hierarchy of RouteSubscriber

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

File

src/EventSubscriber/RouteSubscriber.php, line 19

Namespace

Drupal\tvi\EventSubscriber
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {

    // Update the term router to use the TVI controller.
    if ($route = $collection
      ->get('entity.taxonomy_term.canonical')) {
      $route
        ->setDefault('_controller', '\\Drupal\\tvi\\Controller\\TaxonomyViewsIntegratorTermPageController::render');
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Run after Views subscriber has ran.
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -200,
    ];
    return $events;
  }

}

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