Skip to content

Commit

Permalink
Merge pull request sonata-project#2660 from pulzarraider/translator_c…
Browse files Browse the repository at this point in the history
…heck

Added check if translator service is enabled.
  • Loading branch information
rande committed Jan 5, 2015
2 parents 524d1b1 + 532ce3a commit b6999b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
*/
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();
$groupDefaults = $admins = $classes = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ public function setUp()
$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
*/
Expand Down Expand Up @@ -314,6 +334,12 @@ private function getContainer()
->setArguments(array('', 'Sonata\AdminBundle\Tests\DependencyInjection\Article', 'SonataAdminBundle:CRUD'))
->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;
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"symfony/twig-bridge": "~2.3",
"symfony/class-loader":"~2.3",
"sensio/generator-bundle": "~2.3",
"symfony/translation":"~2.3",
"twig/twig": "~1.15",
"twig/extensions": "~1.0",
"sonata-project/exporter": "~1.0",
Expand Down

0 comments on commit b6999b1

Please sign in to comment.