protected function loadRouteForAction(Admin $admin, Action $action, RouteCollection $routeCollection) { $routingUrlPattern = $admin->getConfiguration()->routingUrlPattern; // routing pattern should contains {admin} and {action} if (strpos($routingUrlPattern, '{admin}') == -1 || strpos($routingUrlPattern, '{action}') == -1) { throw new Exception('Admin routing pattern should contains {admin} and {action} placeholder'); } // route path by entity name and action name $path = str_replace('{admin}', $admin->getEntityPath(), $routingUrlPattern); $path = str_replace('{action}', $action->getName(), $path); // by default, generic controller $defaults = ['_controller' => $admin->getController() . ':' . $action->getName(), '_admin' => $admin->getName(), '_action' => $action->getName()]; // by default, no requirements $requirements = []; // for delete and edit action, an id is required if (in_array($action, ['delete', 'edit'])) { $path .= '/{id}'; $requirements = ['id' => '\\d+']; } // creating new route $route = new Route($path, $defaults, $requirements); $routeName = $admin->generateRouteName($action->getName()); // set route to action $action->setRoute($routeName); // adding route to symfony collection $routeCollection->add($routeName, $route); }