diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index afd315515cbf31f3dc2835c21453b0d7e24a97d9..9fa8631b69b77dff5c5caf16b5c5db2965cacc88 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -697,8 +697,10 @@ $recordRoutes = [ 'worldcatrecord' => 'WorldcatRecord' ]; -// Define list-related routes -- route name => MyResearch action -$listRoutes = ['userList' => 'MyList', 'editList' => 'EditList']; +// Define dynamic routes -- controller => [route name => action] +$dynamicRoutes = [ + 'MyResearch' => ['userList' => 'MyList/[:id]', 'editList' => 'EditList/[:id]'], +]; // Define static routes -- Controller/Action strings $staticRoutes = [ @@ -746,7 +748,7 @@ $staticRoutes = [ $routeGenerator = new \VuFind\Route\RouteGenerator(); $routeGenerator->addRecordRoutes($config, $recordRoutes); -$routeGenerator->addListRoutes($config, $listRoutes); +$routeGenerator->addDynamicRoutes($config, $dynamicRoutes); $routeGenerator->addStaticRoutes($config, $staticRoutes); // Add the home route last diff --git a/module/VuFind/src/VuFind/Route/RouteGenerator.php b/module/VuFind/src/VuFind/Route/RouteGenerator.php index 74273e5b71cce43578dd282642e14a4ecc76132b..dbff777dabcaee46dde40ea8ee696b555981173e 100644 --- a/module/VuFind/src/VuFind/Route/RouteGenerator.php +++ b/module/VuFind/src/VuFind/Route/RouteGenerator.php @@ -70,46 +70,50 @@ class RouteGenerator } /** - * Add a list route to the configuration. + * Add a dynamic route to the configuration. * - * @param array $config Configuration array to update - * @param string $routeName Name of route to generate - * @param string $action MyResearch action + * @param array $config Configuration array to update + * @param string $routeName Name of route to generate + * @param string $controller Controller name + * @param string $action Action and any dynamic parts * * @return void */ - public function addListRoute(& $config, $routeName, $action) + public function addDynamicRoute(& $config, $routeName, $controller, $action) { + list($actionName) = explode('/', $action, 2); $config['router']['routes'][$routeName] = [ 'type' => 'Zend\Mvc\Router\Http\Segment', 'options' => [ - 'route' => '/MyResearch/' . $action . '/[:id]', + 'route' => "/$controller/$action", 'constraints' => [ 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ], 'defaults' => [ - 'controller' => 'MyResearch', - 'action' => $action, + 'controller' => $controller, + 'action' => $actionName, ] ] ]; } /** - * Add list routes to the configuration. + * Add dynamic routes to the configuration. * * @param array $config Configuration array to update - * @param array $routes Associative array (route name => action) of routes - * to add. + * @param array $routes Associative array of arrays + * (controller => [route name => action]) of routes to add. * * @return void */ - public function addListRoutes(& $config, $routes) + public function addDynamicRoutes(& $config, $routes) { - // Build list routes - foreach ($routes as $routeName => $action) { - $this->addListRoute($config, $routeName, $action); + // Build library card routes + foreach ($routes as $controller => $controllerRoutes) { + foreach ($controllerRoutes as $routeName => $action) { + $this->addDynamicRoute($config, $routeName, $controller, $action); + } } }