You are here

public function RouteSubscriber::alterRoutes in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/menu_example/src/Routing/RouteSubscriber.php \Drupal\menu_example\Routing\RouteSubscriber::alterRoutes()

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

menu_example/src/Routing/RouteSubscriber.php, line 23

Class

RouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\menu_example\Routing

Code

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');
}