Browse Source

Added check if translator service is enabled.

Andrej Hudec 10 years ago
parent
commit
532ce3afde

+ 13 - 3
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -31,6 +31,16 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
      */
      */
     public function process(ContainerBuilder $container)
     public function process(ContainerBuilder $container)
     {
     {
+        // check if translator service exist
+        if (!$container->hasAlias('translator')) {
+            throw new \RuntimeException('The "translator" service is not yet enabled.
+                It\'s required by SonataAdmin to display all labels properly.
+
+                To learn how to enable the translator service please visit:
+                http://symfony.com/doc/current/book/translation.html#book-translation-configuration
+             ');
+        }
+
         $parameterBag = $container->getParameterBag();
         $parameterBag = $container->getParameterBag();
         $groupDefaults = $admins = $classes = array();
         $groupDefaults = $admins = $classes = array();
 
 
@@ -172,9 +182,9 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
     /**
     /**
      * Apply the default values required by the AdminInterface to the Admin service definition
      * Apply the default values required by the AdminInterface to the Admin service definition
      *
      *
-     * @param  ContainerBuilder $container
-     * @param  string           $serviceId
-     * @param  array            $attributes
+     * @param ContainerBuilder $container
+     * @param string           $serviceId
+     * @param array            $attributes
      *
      *
      * @return Definition
      * @return Definition
      */
      */

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

@@ -34,6 +34,26 @@ class AddDependencyCallsCompilerPassTest extends \PHPUnit_Framework_TestCase
         $this->config    = $this->getConfig();
         $this->config    = $this->getConfig();
     }
     }
 
 
+    public function testTranslatorDisabled()
+    {
+        $this->setExpectedException(
+          'RuntimeException', 'The "translator" service is not yet enabled.
+                It\'s required by SonataAdmin to display all labels properly.
+
+                To learn how to enable the translator service please visit:
+                http://symfony.com/doc/current/book/translation.html#book-translation-configuration
+             '
+        );
+
+        $container = $this->getContainer();
+        $container->removeAlias('translator');
+        $this->extension->load(array($this->config), $container);
+
+        $compilerPass = new AddDependencyCallsCompilerPass();
+        $compilerPass->process($container);
+        $container->compile();
+    }
+
     /**
     /**
      * @covers Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass::process
      * @covers Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass::process
      */
      */
@@ -314,6 +334,12 @@ class AddDependencyCallsCompilerPassTest extends \PHPUnit_Framework_TestCase
             ->setArguments(array('', 'Sonata\AdminBundle\Tests\DependencyInjection\Article', 'SonataAdminBundle:CRUD'))
             ->setArguments(array('', 'Sonata\AdminBundle\Tests\DependencyInjection\Article', 'SonataAdminBundle:CRUD'))
             ->addTag('sonata.admin', array('group' => 'sonata_group_one', 'manager_type' => 'doctrine_phpcr'));
             ->addTag('sonata.admin', array('group' => 'sonata_group_one', 'manager_type' => 'doctrine_phpcr'));
 
 
+        // translator
+        $container
+            ->register('translator.default')
+            ->setClass('Symfony\Bundle\FrameworkBundle\Translation\Translator');
+        $container->setAlias('translator', 'translator.default');
+
         return $container;
         return $container;
     }
     }
 }
 }

+ 1 - 0
composer.json

@@ -27,6 +27,7 @@
         "symfony/twig-bridge": "~2.3",
         "symfony/twig-bridge": "~2.3",
         "symfony/class-loader":"~2.3",
         "symfony/class-loader":"~2.3",
         "sensio/generator-bundle": "~2.3",
         "sensio/generator-bundle": "~2.3",
+        "symfony/translation":"~2.3",
         "twig/twig": "~1.15",
         "twig/twig": "~1.15",
         "twig/extensions": "~1.0",
         "twig/extensions": "~1.0",
         "sonata-project/exporter": "~1.0",
         "sonata-project/exporter": "~1.0",