Skip to content

Commit

Permalink
Improve error message for non existent admin declaration (#8025)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Mar 24, 2023
1 parent 83013ce commit 361214d
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions src/DependencyInjection/Compiler/AdminSearchCompilerPass.php
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\AdminBundle\DependencyInjection\Compiler;

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\DependencyInjection\Admin\TaggedAdminInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -39,8 +38,6 @@ public function process(ContainerBuilder $container): void
$adminSearch = [];

foreach ($container->findTaggedServiceIds(TaggedAdminInterface::ADMIN_TAG) as $id => $tags) {
$this->validateAdminClass($container, $id);

foreach ($tags as $attributes) {
$globalSearch = $this->getGlobalSearchValue($attributes, $id);
if (null === $globalSearch) {
Expand All @@ -56,30 +53,6 @@ public function process(ContainerBuilder $container): void
$searchHandlerDefinition->addMethodCall('configureAdminSearch', [$adminSearch]);
}

/**
* @throws LogicException if the class in the given service definition is not
* a subclass of `AdminInterface`
*/
private function validateAdminClass(ContainerBuilder $container, string $id): void
{
$definition = $container->getDefinition($id);

// Trim possible parameter delimiters ("%") from the class name.
$adminClass = trim($definition->getClass() ?? '', '%');
if (!class_exists($adminClass) && $container->hasParameter($adminClass)) {
$adminClass = $container->getParameter($adminClass);
\assert(\is_string($adminClass));
}

if (!is_subclass_of($adminClass, AdminInterface::class)) {
throw new LogicException(sprintf(
'Service "%s" must implement `%s`.',
$id,
AdminInterface::class
));
}
}

/**
* @param array<string, mixed> $attributes
*
Expand Down

0 comments on commit 361214d

Please sign in to comment.