class RouteSubscriber in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/menu_example/src/Routing/RouteSubscriber.php \Drupal\menu_example\Routing\RouteSubscriber
Listens to the dynamic route events.
The \Drupal\Core\Routing\RouteSubscriberBase class contains an event listener that listens to this event. We alter existing routes by implementing the alterRoutes(RouteCollection $collection) method of this class.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\menu_example\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
See also
https://www.drupal.org/docs/8/api/routing-system/altering-existing-route...
1 string reference to 'RouteSubscriber'
- menu_example.services.yml in menu_example/
menu_example.services.yml - menu_example/menu_example.services.yml
1 service uses RouteSubscriber
File
- menu_example/
src/ Routing/ RouteSubscriber.php, line 18
Namespace
Drupal\menu_example\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
// Get the path from RouteCollection.
$route = $collection
->get('example.menu_example.path_override');
// Set the new path.
$route
->setPath('/examples/menu-example/menu-altered-path');
// Change title to indicate changes.
$route
->setDefault('_title', 'Menu item altered by RouteSubscriber::alterRoutes');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
public | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
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 |