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
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\tvi\EventSubscriber\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
EventSubscriber/ RouteSubscriber.php, line 19
Namespace
Drupal\tvi\EventSubscriberView 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
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 |