Skip to content

Commit

Permalink
Add getRouteName method
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jan 19, 2021
1 parent c4b1574 commit 3d94b67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,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)
Expand Down
8 changes: 6 additions & 2 deletions src/Route/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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, '\\') ? ':' : '::';
Expand All @@ -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);
Expand Down

0 comments on commit 3d94b67

Please sign in to comment.