class RouteSubscriber in Page Manager 8
Same name and namespace in other branches
- 8.4 tests/modules/page_manager_routing_test/src/Routing/RouteSubscriber.php \Drupal\page_manager_routing_test\Routing\RouteSubscriber
Route subscriber for Page Manager Routing Test.
Hierarchy
- class \Drupal\page_manager_routing_test\Routing\RouteSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RouteSubscriber
1 string reference to 'RouteSubscriber'
- page_manager_routing_test.services.yml in tests/
modules/ page_manager_routing_test/ page_manager_routing_test.services.yml - tests/modules/page_manager_routing_test/page_manager_routing_test.services.yml
1 service uses RouteSubscriber
- page_manager_routing_test.subscriber in tests/
modules/ page_manager_routing_test/ page_manager_routing_test.services.yml - Drupal\page_manager_routing_test\Routing\RouteSubscriber
File
- tests/
modules/ page_manager_routing_test/ src/ Routing/ RouteSubscriber.php, line 13
Namespace
Drupal\page_manager_routing_test\RoutingView source
class RouteSubscriber implements EventSubscriberInterface {
/**
* Alters the existing route collection.
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The route build event.
*/
public function beforePageManagerRoutes(RouteBuildEvent $event) {
$collection = $event
->getRouteCollection();
$route = new Route('/entity_test/{entity_test}', [], [
'_access' => 'TRUE',
]);
$route
->setRequirement('_format', 'xml');
$collection
->add('entity.entity_test.canonical.xml', $route);
}
/**
* Alters the existing route collection.
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The route build event.
*/
public function afterPageManagerRoutes(RouteBuildEvent $event) {
$collection = $event
->getRouteCollection();
if ($original_route = $collection
->get('entity.entity_test.canonical')) {
$route = new Route($original_route
->getPath(), $original_route
->getDefaults(), $original_route
->getRequirements(), $original_route
->getOptions());
$route
->setRequirement('_format', 'json');
$collection
->add('entity.entity_test.canonical.json', $route);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Run before PageManagerRoutes.
$events[RoutingEvents::ALTER][] = [
'beforePageManagerRoutes',
-155,
];
// Run after PageManagerRoutes.
$events[RoutingEvents::ALTER][] = [
'afterPageManagerRoutes',
-165,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
public | function | Alters the existing route collection. | |
RouteSubscriber:: |
public | function | Alters the existing route collection. | |
RouteSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. |