diff --git a/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index 89e65e387c..675df5bcfd 100644 --- a/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -279,7 +279,7 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at 'menu_factory' => 'knp_menu.factory', 'route_builder' => 'sonata.admin.route.path_info'. (($manager_type == 'doctrine_phpcr') ? '_slashes' : ''), - 'label_translator_strategy' => 'sonata.admin.label.strategy.native', + 'label_translator_strategy' => null !== $settings['label_translator_strategy'] ? $settings['label_translator_strategy'] : 'sonata.admin.label.strategy.native', ); $definition->addMethodCall('setManagerType', array($manager_type)); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 472dc97f5b..229da852e5 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -245,36 +245,35 @@ public function getConfigTreeBuilder() ->end() ->end() ->arrayNode('admin_services') - ->prototype('array') - ->children() - ->scalarNode('model_manager')->defaultNull()->end() - ->scalarNode('form_contractor')->defaultNull()->end() - ->scalarNode('show_builder')->defaultNull()->end() - ->scalarNode('list_builder')->defaultNull()->end() - ->scalarNode('datagrid_builder')->defaultNull()->end() - ->scalarNode('translator')->defaultNull()->end() - ->scalarNode('configuration_pool')->defaultNull()->end() - ->scalarNode('route_generator')->defaultNull()->end() - ->scalarNode('validator')->defaultNull()->end() - ->scalarNode('security_handler')->defaultNull()->end() - ->scalarNode('label')->defaultNull()->end() - ->scalarNode('menu_factory')->defaultNull()->end() - ->scalarNode('route_builder')->defaultNull()->end() - ->scalarNode('label_translator_strategy')->defaultNull()->end() - ->scalarNode('pager_type')->defaultNull()->end() - ->arrayNode('templates') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('form') - ->prototype('scalar')->end() - ->end() - ->arrayNode('filter') - ->prototype('scalar')->end() - ->end() - ->arrayNode('view') - ->useAttributeAsKey('id') - ->prototype('scalar')->end() - ->end() + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('model_manager')->defaultNull()->end() + ->scalarNode('form_contractor')->defaultNull()->end() + ->scalarNode('show_builder')->defaultNull()->end() + ->scalarNode('list_builder')->defaultNull()->end() + ->scalarNode('datagrid_builder')->defaultNull()->end() + ->scalarNode('translator')->defaultNull()->end() + ->scalarNode('configuration_pool')->defaultNull()->end() + ->scalarNode('route_generator')->defaultNull()->end() + ->scalarNode('validator')->defaultNull()->end() + ->scalarNode('security_handler')->defaultNull()->end() + ->scalarNode('label')->defaultNull()->end() + ->scalarNode('menu_factory')->defaultNull()->end() + ->scalarNode('route_builder')->defaultNull()->end() + ->scalarNode('label_translator_strategy')->defaultNull()->end() + ->scalarNode('pager_type')->defaultNull()->end() + ->arrayNode('templates') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('form') + ->prototype('scalar')->end() + ->end() + ->arrayNode('filter') + ->prototype('scalar')->end() + ->end() + ->arrayNode('view') + ->useAttributeAsKey('id') + ->prototype('scalar')->end() ->end() ->end() ->end() diff --git a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php index b5bfe10dee..e7f4fc812e 100644 --- a/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php @@ -521,6 +521,50 @@ public function testProcessAbstractAdminServiceInServiceDefinition() $this->assertSame('extra_argument_2', $definition->getArgument(3)); } + + /** + * By default label translation policy is 'sonata.admin.label.strategy.native'. + */ + public function testLabelTranslationStrategyDefaultConfig() + { + $container = $this->getContainer(); + + $this->extension->load(array(), $container); + + $compilerPass = new AddDependencyCallsCompilerPass(); + $compilerPass->process($container); + + $container->compile(); + + $this->assertContains('sonata.admin.label.strategy.native', $container->getServiceIds()); + } + + /** + * Overwritten default label translation policy service should be available in a services pool. + * + * @depends testLabelTranslationStrategyDefaultConfig + */ + public function testLabelTranslationStrategyOverwrittenConfig() + { + $config = array( + 'sonata_admin' => array( + 'admin_services' => array( + 'label_translator_strategy' => 'sonata.admin.label.strategy.underscore' + ) + ) + ); + $container = $this->getContainer(); + + $this->extension->load($config, $container); + + $compilerPass = new AddDependencyCallsCompilerPass(); + $compilerPass->process($container); + + $container->compile(); + + $this->assertContains('sonata.admin.label.strategy.underscore', $container->getServiceIds()); + } + /** * @return array */