class RouteSubscriber in Workspace 8
Subscriber for Workspace routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\workspace\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 14
Namespace
Drupal\workspace\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* @var \Drupal\multiversion\MultiversionManagerInterface
*/
protected $multiversionManager;
/**
* Constructs a new RouteSubscriber object.
*
* @param \Drupal\multiversion\MultiversionManagerInterface $multiversion_manager
*/
public function __construct(MultiversionManagerInterface $multiversion_manager) {
$this->multiversionManager = $multiversion_manager;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->multiversionManager
->getEnabledEntityTypes() as $entity_type_id => $entity_type) {
if ($entity_type
->hasLinkTemplate('version-tree')) {
$options = [
'_admin_route' => TRUE,
'_entity_type_id' => $entity_type_id,
'parameters' => [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
],
];
if ($link_template = $entity_type
->getLinkTemplate('version-tree')) {
$route = new Route($link_template, [
'_controller' => '\\Drupal\\workspace\\Controller\\RevisionsController::revisions',
'_title' => 'Revisions',
], [
'_permission' => 'view_revision_trees',
], $options);
// This will create new routes
$collection
->add("entity.{$entity_type_id}.version_tree", $route);
}
if (($link_template = $entity_type
->getLinkTemplate('revision')) && empty($collection
->get("entity.{$entity_type_id}.revision"))) {
unset($options['_admin_route']);
$options['parameters']['entity_revision'] = [
'type' => 'entity_revision:' . $entity_type_id,
];
$route = new Route($link_template, [
'_controller' => '\\Drupal\\workspace\\Controller\\RevisionController::view',
'_title_callback' => '\\Drupal\\workspace\\Controller\\RevisionController::viewTitle',
], [
'_permission' => 'view_revision_trees',
], $options);
// This will create new routes (and override the revision
// route for entity types that already has one).
$collection
->add("entity.{$entity_type_id}.revision", $route);
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
100,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | ||
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:: |
|
RouteSubscriber:: |
public | function | Constructs a new RouteSubscriber object. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |