class WebformRouteSubscriber in Webform 8.5
Same name and namespace in other branches
- 6.x src/Routing/WebformRouteSubscriber.php \Drupal\webform\Routing\WebformRouteSubscriber
Adds the _admin_route option to webform routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\webform\Routing\WebformRouteSubscriber
Expanded class hierarchy of WebformRouteSubscriber
1 string reference to 'WebformRouteSubscriber'
1 service uses WebformRouteSubscriber
File
- src/
Routing/ WebformRouteSubscriber.php, line 13
Namespace
Drupal\webform\RoutingView source
class WebformRouteSubscriber extends RouteSubscriberBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The configuration object factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a WebformShareRouteSubscriber object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration object factory.
*/
public function __construct(ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory = NULL) {
$this->moduleHandler = $module_handler;
$this->configFactory = $config_factory ?: \Drupal::configFactory();
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// Set admin route for webform admin routes.
foreach ($collection
->all() as $route) {
if (!$route
->hasOption('_admin_route') && (strpos($route
->getPath(), '/admin/structure/webform/') === 0 || strpos($route
->getPath(), '/webform/results/') !== FALSE)) {
$route
->setOption('_admin_route', TRUE);
}
// Change /admin/structure/webform/ to /admin/webform/.
if ($this->configFactory
->get('webform.settings')
->get('ui.toolbar_item')) {
if (strpos($route
->getPath(), '/admin/structure/webform') === 0) {
$path = str_replace('/admin/structure/webform', '/admin/webform', $route
->getPath());
$route
->setPath($path);
}
}
}
// If the webform_share.module is not enabled, remove variant share route.
if (!$this->moduleHandler
->moduleExists('webform_share')) {
$collection
->remove('entity.webform.variant.share_form');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 |
WebformRouteSubscriber:: |
protected | property | The configuration object factory. | |
WebformRouteSubscriber:: |
protected | property | The module handler. | |
WebformRouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
WebformRouteSubscriber:: |
public | function | Constructs a WebformShareRouteSubscriber object. |