class RouteSubscriber
Same name in other branches
- 3.x modules/menu_example/src/Routing/RouteSubscriber.php \Drupal\menu_example\Routing\RouteSubscriber
- 4.0.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\menu_example\Routing\RouteSubscriber extends \Drupal\Core\Routing\RouteSubscriberBase
Expanded class hierarchy of RouteSubscriber
See also
https://www.drupal.org/docs/8/api/routing-system/altering-existing-rout…
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
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
RouteSubscriber::alterRoutes | public | function |