diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index b7af06402d..c4b4508e91 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -338,7 +338,7 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at $method = $this->generateSetterMethodName($attr); - if (isset($overwriteAdminConfiguration[$attr]) || !$definition->hasMethodCall($method)) { + if (!$definition->hasMethodCall($method)) { $args = [new Reference($overwriteAdminConfiguration[$attr] ?? $addServiceId)]; if ('translator' === $attr) { $args[] = false; diff --git a/tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index 0333e0f2b6..c2af8d154b 100644 --- a/tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; /** * @author Tiago Garcia @@ -213,6 +214,12 @@ public function testProcessResultingConfig(): void [[]] ); + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( + 'sonata_news_admin', + 'setModelManager', + [new Reference('my.model.manager')] + ); + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( 'sonata_article_admin', 'setFormTheme', @@ -668,7 +675,8 @@ private function setUpContainer(): void ->setPublic(true) ->setClass(MockAdmin::class) ->setArguments(['', News::class, CRUDController::class]) - ->addTag('sonata.admin', ['group' => 'sonata_group_two', 'label' => '5 Entry', 'manager_type' => 'orm']); + ->addTag('sonata.admin', ['group' => 'sonata_group_two', 'label' => '5 Entry', 'manager_type' => 'orm']) + ->addMethodCall('setModelManager', [new Reference('my.model.manager')]); $this->container ->register('sonata_post_admin') ->setClass(MockAdmin::class)