Kaynağa Gözat

Accept translator defined as service without alias (#4532)

Translator can be disabled in the FrameworkBundle config.
In this case an IdentityTranslator (that does nothing) is
still registered by the FrameworkBundle as a "translator"
service (but as not an alias).

This commit makes Sonata Admin accepts any "translator"
service (being an alias or not).
Loïck Piera 8 yıl önce
ebeveyn
işleme
b5b821618a

+ 1 - 1
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -34,7 +34,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
     public function process(ContainerBuilder $container)
     {
         // check if translator service exist
-        if (!$container->hasAlias('translator')) {
+        if (!$container->has('translator')) {
             throw new \RuntimeException('The "translator" service is not yet enabled.
                 It\'s required by SonataAdmin to display all labels properly.
 

+ 1 - 0
Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php

@@ -49,6 +49,7 @@ class AddDependencyCallsCompilerPassTest extends PHPUnit_Framework_TestCase
 
         $container = $this->getContainer();
         $container->removeAlias('translator');
+        $container->removeDefinition('translator');
         $this->extension->load(array($this->config), $container);
 
         $compilerPass = new AddDependencyCallsCompilerPass();