diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index b373c21949..43e6e87268 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -1176,7 +1176,7 @@ public function isCurrentRoute($name, $adminCode = null) return false; } - return sprintf('%s_%s', $admin->getBaseRouteName(), $name) === $route; + return $admin->getRoutes()->getRouteName($name) === $route; } public function generateObjectUrl($name, $object, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) diff --git a/src/Route/RouteCollection.php b/src/Route/RouteCollection.php index f86f2262c2..3faa5f0631 100644 --- a/src/Route/RouteCollection.php +++ b/src/Route/RouteCollection.php @@ -66,6 +66,11 @@ public function __construct($baseCodeRoute, $baseRouteName, $baseRoutePattern, $ $this->baseControllerName = $baseControllerName; } + public function getRouteName(string $name): string + { + return sprintf('%s_%s', $this->baseRouteName, $name); + } + /** * Add route. * @@ -89,7 +94,6 @@ public function add( ) { $pattern = sprintf('%s/%s', $this->baseRoutePattern, $pattern ?: $name); $code = $this->getCode($name); - $routeName = sprintf('%s_%s', $this->baseRouteName, $name); if (!isset($defaults['_controller'])) { $actionJoiner = false === strpos($this->baseControllerName, '\\') ? ':' : '::'; @@ -104,7 +108,7 @@ public function add( $defaults['_sonata_admin'] = $this->baseCodeRoute; } - $defaults['_sonata_name'] = $routeName; + $defaults['_sonata_name'] = $this->getRouteName($name); $element = static function () use ($pattern, $defaults, $requirements, $options, $host, $schemes, $methods, $condition) { return new Route($pattern, $defaults, $requirements, $options, $host, $schemes, $methods, $condition); diff --git a/src/Route/RouteCollectionInterface.php b/src/Route/RouteCollectionInterface.php index 4986b71be3..9f14c1d476 100644 --- a/src/Route/RouteCollectionInterface.php +++ b/src/Route/RouteCollectionInterface.php @@ -17,6 +17,8 @@ /** * @author Jordi Sala + * + * @method string getRouteName(string $name) */ interface RouteCollectionInterface { @@ -123,6 +125,9 @@ public function getBaseControllerName(); */ public function getBaseRouteName(); + // NEXT_MAJOR: Uncomment the following line and remove corresponding @method annotation. +// public function getRouteName(string $name): string; + /** * @return string */