Skip to content

Commit

Permalink
Add getRouteName method
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and greg0ire committed Jan 25, 2021
1 parent 712ca6b commit c5590a1
Show file tree
Hide file tree
Showing 3 changed files with 12 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 @@ -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)
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
5 changes: 5 additions & 0 deletions src/Route/RouteCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* @author Jordi Sala <[email protected]>
*
* @method string getRouteName(string $name)
*/
interface RouteCollectionInterface
{
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit c5590a1

Please sign in to comment.