class RouteSubscriber in Views Advanced Routing 8
Same name and namespace in other branches
- 2.x src/Routing/RouteSubscriber.php \Drupal\views_advanced_routing\Routing\RouteSubscriber
Customizes Views routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\views_advanced_routing\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 20 - Contains \Drupal\views_advanced_routing\Routing\RouteSubscriber.
Namespace
Drupal\views_advanced_routing\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* The view storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $viewStorage;
/**
* Constructs a RouteSubscriber object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->viewStorage = $entity_manager
->getStorage('view');
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
$views = [];
foreach (Views::getApplicableViews('uses_route') as $data) {
list($view_id, $display_id) = $data;
$views[$view_id][] = $display_id;
}
foreach ($views as $view_id => $displays) {
/** @var \Drupal\views\Entity\View $view */
$view = $this->viewStorage
->load($view_id);
foreach ($displays as $display_id) {
if (($vex = $view
->getExecutable()) && $vex instanceof ViewExecutable) {
if ($vex
->setDisplay($display_id) && ($display = $vex->displayHandlers
->get($display_id))) {
if ($display instanceof DisplayRouterInterface) {
$options = $display
->getOption('display_extenders');
if (isset($options['views_advanced_routing_route'])) {
$route = $collection
->get($display
->getRouteName());
$settings = $options['views_advanced_routing_route'];
if ($route && !empty($settings['route'])) {
$route_info = $settings['route'];
$route_info += [
'defaults' => [],
'requirements' => [],
'options' => [],
];
$route
->addOptions($route_info['options'])
->addRequirements($route_info['requirements'])
->addDefaults($route_info['defaults']);
$collection
->add($display
->getRouteName(), $route);
}
}
}
}
$vex
->destroy();
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The view storage. | |
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public | function | Constructs a RouteSubscriber object. | |
RouteSubscriberBase:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | 5 |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |