class RouteSubscriber in Webform Views Integration 8.5
Alter the routes in order to allow multiple views on the same route.
Alter the routes so '{webform}' parameter is present and defaults to the corresponding webform for all views that are related to webform submissions.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\webform_views\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 16
Namespace
Drupal\webform_views\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* @var StateInterface
*/
protected $state;
/**
* @var EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* RouteSubscriber constructor.
*/
public function __construct(StateInterface $state, EntityTypeManagerInterface $entity_type_manager) {
$this->state = $state;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
$view_route_names = $this->state
->get('views.view_route_names');
foreach (webform_views_applicable_views() as $trio) {
list($view_id, $display_id, $path) = $trio;
$route_name = $view_route_names[$view_id . '.' . $display_id];
if (($route = $collection
->get($route_name)) && ($webform_id = webform_views_webform_id_from_path($path))) {
$route
->setPath($route
->getPath() . '/{webform}');
$route
->setDefault('webform', $webform_id);
$options = $route
->getOptions();
$options['parameters']['webform']['type'] = 'entity:webform';
$route
->setOptions($options);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | ||
RouteSubscriber:: |
protected | property | ||
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public | function | RouteSubscriber constructor. | |
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 |