class MenuExampleDynamicRoutes in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/menu_example/src/Routing/MenuExampleDynamicRoutes.php \Drupal\menu_example\Routing\MenuExampleDynamicRoutes
Defines dynamic routes for our tab menu items.
These routes support the links created in menu_example.links.task.yml.
Hierarchy
- class \Drupal\menu_example\Routing\MenuExampleDynamicRoutes
Expanded class hierarchy of MenuExampleDynamicRoutes
See also
https://www.drupal.org/docs/8/api/routing-system/providing-dynamic-routes
File
- menu_example/
src/ Routing/ MenuExampleDynamicRoutes.php, line 15
Namespace
Drupal\menu_example\RoutingView source
class MenuExampleDynamicRoutes {
/**
* Returns an array of route objects.
*
* @return \Symfony\Component\Routing\Route[]
* An array of route objects.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuExampleDynamicRoutes:: |
public | function | Returns an array of route objects. |