MenuExampleDynamicRoutes.php in Examples for Developers 8
File
menu_example/src/Routing/MenuExampleDynamicRoutes.php
View source
<?php
namespace Drupal\menu_example\Routing;
use Symfony\Component\Routing\Route;
class MenuExampleDynamicRoutes {
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;
}
}