class RouteSubscriber
Same name in other branches
- 8.x-1.x 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\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- 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 modules/
menu_example/ menu_example.services.yml - modules/menu_example/menu_example.services.yml
1 service uses RouteSubscriber
- menu_example.route_subscriber in modules/
menu_example/ menu_example.services.yml - Drupal\menu_example\Routing\RouteSubscriber
File
-
modules/
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 | Overriden Title | Overrides |
---|---|---|---|---|---|
RouteSubscriber::alterRoutes | public | function | Alters existing routes for a specific collection. | Overrides RouteSubscriberBase::alterRoutes | |
RouteSubscriberBase::getSubscribedEvents | public static | function | 7 | ||
RouteSubscriberBase::onAlterRoutes | public | function | Delegates the route altering to self::alterRoutes(). | 1 |