Skip to content

Commit

Permalink
Fix support for full name route (#7666)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Dec 23, 2021
1 parent 670fc2e commit 8ea23e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Route/DefaultRouteGenerator.php
Expand Up @@ -140,14 +140,17 @@ private function getCode(AdminInterface $admin, string $name): string

$codePrefix = $admin->getBaseCodeRoute();

// someone provide a code, so it is a child
if (strpos($name, '.') > 0) {
return sprintf('%s|%s', $codePrefix, $name);
// Someone provided the full name
if (
0 === strpos($name, sprintf('%s|', $codePrefix)) // Child admin route already prefixed
|| 0 === strpos($name, sprintf('%s.', $codePrefix)) // admin route already prefixed
) {
return $name;
}

// someone provide the fullname
if (!$admin->isChild() && \array_key_exists($name, $this->caches)) {
return $name;
// Someone provided a code, so it is a child
if (strpos($name, '.') > 0) {
return sprintf('%s|%s', $codePrefix, $name);
}

return sprintf('%s.%s', $codePrefix, $name);
Expand Down
3 changes: 3 additions & 0 deletions tests/Route/DefaultRouteGeneratorTest.php
Expand Up @@ -241,8 +241,11 @@ public function getGenerateUrlChildTests(): array
{
return [
['parent', '/foo?id=123&default_param=default_val', 'foo', ['id' => 123, 'default_param' => 'default_val']],
['parent', '/foo?id=123&default_param=default_val', 'base.Code.Parent.foo', ['id' => 123, 'default_param' => 'default_val']],
['parent', '/foo/bar?id=123&default_param=default_val', 'base.Code.Child.bar', ['id' => 123, 'default_param' => 'default_val']],
['parent', '/foo/bar?id=123&default_param=default_val', 'base.Code.Parent|base.Code.Child.bar', ['id' => 123, 'default_param' => 'default_val']],
['child', '/foo/bar?abc=a123&efg=e456&default_param=default_val&childId=987654', 'bar', ['id' => 123, 'default_param' => 'default_val']],
['child', '/foo/bar?abc=a123&efg=e456&default_param=default_val&childId=987654', 'base.Code.Parent|base.Code.Child.bar', ['id' => 123, 'default_param' => 'default_val']],
];
}

Expand Down

0 comments on commit 8ea23e2

Please sign in to comment.