You are here

public function MenuExampleDynamicRoutes::routes in Examples for Developers 8

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

Returns an array of route objects.

Return value

\Symfony\Component\Routing\Route[] An array of route objects.

1 string reference to 'MenuExampleDynamicRoutes::routes'
menu_example.routing.yml in menu_example/menu_example.routing.yml
menu_example/menu_example.routing.yml

File

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

Class

MenuExampleDynamicRoutes
Defines dynamic routes for our tab menu items.

Namespace

Drupal\menu_example\Routing

Code

public function routes() {
  $routes = [];
  $tabs = [
    'tabs' => 'Default primary tab',
    'tabs/second' => 'Second',
    'tabs/third' => 'Third',
    'tabs/fourth' => 'Fourth',
    'tabs/default/second' => 'Second',
    'tabs/default/third' => 'Third',
  ];
  foreach ($tabs as $path => $title) {
    $machine_name = 'examples.menu_example.' . str_replace('/', '_', $path);
    $routes[$machine_name] = new Route('/examples/menu-example/' . $path, [
      '_controller' => '\\Drupal\\menu_example\\Controller\\MenuExampleController::tabsPage',
      '_title' => $title,
      'path' => $path,
      'title' => $title,
    ], [
      '_access' => 'TRUE',
    ]);
  }
  return $routes;
}