diff --git a/src/ArgumentResolver/AdminValueResolver.php b/src/ArgumentResolver/AdminValueResolver.php index ffb1ac70e3b..7d7f41ddfc7 100644 --- a/src/ArgumentResolver/AdminValueResolver.php +++ b/src/ArgumentResolver/AdminValueResolver.php @@ -31,7 +31,12 @@ public function __construct(AdminFetcherInterface $adminFetcher) public function supports(Request $request, ArgumentMetadata $argument): bool { $type = $argument->getType(); - if (null === $type || !is_subclass_of($type, AdminInterface::class)) { + + if (null === $type) { + return false; + } + + if (AdminInterface::class !== $type && !is_subclass_of($type, AdminInterface::class)) { return false; } diff --git a/tests/ArgumentResolver/AdminValueResolverTest.php b/tests/ArgumentResolver/AdminValueResolverTest.php index 4f854b20bde..3a49706ced9 100644 --- a/tests/ArgumentResolver/AdminValueResolverTest.php +++ b/tests/ArgumentResolver/AdminValueResolverTest.php @@ -14,6 +14,7 @@ namespace Sonata\AdminBundle\Tests\ArgumentResolver; use PHPUnit\Framework\TestCase; +use Sonata\AdminBundle\Admin\AdminInterface; use Sonata\AdminBundle\Admin\Pool; use Sonata\AdminBundle\ArgumentResolver\AdminValueResolver; use Sonata\AdminBundle\Request\AdminFetcher; @@ -93,6 +94,12 @@ public function supportDataProvider(): iterable $request, new ArgumentMetadata('_sonata_admin', PostAdmin::class, false, false, null), ]; + + yield 'Admin can fetch by interface' => [ + true, + $request, + new ArgumentMetadata('_sonata_admin', AdminInterface::class, false, false, null), + ]; } public function testResolveAdmin(): void