From c209e9991036f5cfda08044b40cb2429585a65d2 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 16 Apr 2021 11:28:38 +0200 Subject: [PATCH] Add default_admin_services node --- .../recipe_overwrite_admin_configuration.rst | 49 +++++++++---------- docs/reference/configuration.rst | 2 +- .../AddDependencyCallsCompilerPass.php | 7 ++- src/DependencyInjection/Configuration.php | 37 ++++++++++++++ .../SonataAdminExtension.php | 2 + .../DependencyInjection/ConfigurationTest.php | 11 +++++ 6 files changed, 80 insertions(+), 28 deletions(-) diff --git a/docs/cookbook/recipe_overwrite_admin_configuration.rst b/docs/cookbook/recipe_overwrite_admin_configuration.rst index 9205d37575f..a974a92fd66 100644 --- a/docs/cookbook/recipe_overwrite_admin_configuration.rst +++ b/docs/cookbook/recipe_overwrite_admin_configuration.rst @@ -12,30 +12,29 @@ with the following templates: sonata_admin: admin_services: - id.of.admin.service: - # service configuration - model_manager: sonata.admin.manager.orm - data_source: sonata.admin.data_source.orm - form_contractor: sonata.admin.builder.orm_form - show_builder: sonata.admin.builder.orm_show - list_builder: sonata.admin.builder.orm_list - datagrid_builder: sonata.admin.builder.orm_datagrid - translator: translator - configuration_pool: sonata.admin.pool - route_generator: sonata.admin.route.default_generator - validator: validator - security_handler: sonata.admin.security.handler - menu_factory: knp_menu.factory - route_builder: sonata.admin.route.path_info - label_translator_strategy: sonata.admin.label.strategy.native + # service configuration + model_manager: sonata.admin.manager.orm + data_source: sonata.admin.data_source.orm + form_contractor: sonata.admin.builder.orm_form + show_builder: sonata.admin.builder.orm_show + list_builder: sonata.admin.builder.orm_list + datagrid_builder: sonata.admin.builder.orm_datagrid + translator: translator + configuration_pool: sonata.admin.pool + route_generator: sonata.admin.route.default_generator + validator: validator + security_handler: sonata.admin.security.handler + menu_factory: knp_menu.factory + route_builder: sonata.admin.route.path_info + label_translator_strategy: sonata.admin.label.strategy.native - # templates configuration - templates: - # view templates - view: - user_block: mytemplate.twig.html - # form related theme templates => this feature need to be implemented by the Persistency layer of each Admin Bundle - form: ['MyTheme.twig.html', 'MySecondTheme.twig.html'] - filter: ['MyTheme.twig.html', 'MySecondTheme.twig.html'] + # templates configuration + templates: + # view templates + view: + user_block: mytemplate.twig.html + # form related theme templates => this feature need to be implemented by the Persistency layer of each Admin Bundle + form: ['MyTheme.twig.html', 'MySecondTheme.twig.html'] + filter: ['MyTheme.twig.html', 'MySecondTheme.twig.html'] -With these settings you will be able to change default services and templates used by the ``id.of.admin.service`` admin instance. +With these settings you will be able to change default services and templates used by the admin instance. diff --git a/docs/reference/configuration.rst b/docs/reference/configuration.rst index 6fdc59e0a66..7e8155178f0 100644 --- a/docs/reference/configuration.rst +++ b/docs/reference/configuration.rst @@ -119,7 +119,7 @@ Full Configuration Options id: ~ position: right class: col-md-4 - admin_services: + default_admin_services: model_manager: null data_source: null form_contractor: null diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index a349a8f7d7e..d37cc8ae33d 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -261,7 +261,7 @@ public function applyConfigurationFromAttribute(Definition $definition, array $a 'datagrid_builder', 'translator', 'configuration_pool', - 'router', + 'route_generator', 'validator', // NEXT_MAJOR: Remove this line 'security_handler', 'menu_factory', @@ -292,13 +292,16 @@ public function applyConfigurationFromAttribute(Definition $definition, array $a public function applyDefaults(ContainerBuilder $container, $serviceId, array $attributes = []) { $definition = $container->getDefinition($serviceId); + // NEXT_MAJOR: Remove this line. $settings = $container->getParameter('sonata.admin.configuration.admin_services'); $definition->setShared(false); $managerType = $attributes['manager_type']; - $overwriteAdminConfiguration = $settings[$serviceId] ?? []; + // NEXT_MAJOR: Remove this line and uncomment the following + $overwriteAdminConfiguration = $settings[$serviceId] ?? $container->getParameter('sonata.admin.configuration.default_admin_services') ?? []; +// $overwriteAdminConfiguration = $container->getParameter('sonata.admin.configuration.default_admin_services') ?? []; $defaultAddServices = [ 'model_manager' => sprintf('sonata.admin.manager.%s', $managerType), diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 6d2a10c30a8..b67db2c6fa1 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -344,11 +344,48 @@ public function getConfigTreeBuilder() ->end() ->end() ->end() + ->arrayNode('default_admin_services') + ->children() + ->scalarNode('model_manager')->defaultNull()->end() + ->scalarNode('data_source')->defaultNull()->end() + ->scalarNode('field_description_factory')->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('security_handler')->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() + ->end() + ->end() + // NEXT_MAJOR: Remove this node. ->arrayNode('admin_services') + ->setDeprecated('The "%node%" option is deprecated since sonata-project/admin-bundle 3.x.') ->prototype('array') ->children() ->scalarNode('model_manager')->defaultNull()->end() ->scalarNode('data_source')->defaultNull()->end() + ->scalarNode('field_description_factory')->defaultNull()->end() ->scalarNode('form_contractor')->defaultNull()->end() ->scalarNode('show_builder')->defaultNull()->end() ->scalarNode('list_builder')->defaultNull()->end() diff --git a/src/DependencyInjection/SonataAdminExtension.php b/src/DependencyInjection/SonataAdminExtension.php index 600c87beebc..dea58f069e1 100644 --- a/src/DependencyInjection/SonataAdminExtension.php +++ b/src/DependencyInjection/SonataAdminExtension.php @@ -118,6 +118,8 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('sonata.admin.configuration.global_search.empty_boxes', $config['global_search']['empty_boxes']); $container->setParameter('sonata.admin.configuration.global_search.case_sensitive', $config['global_search']['case_sensitive']); $container->setParameter('sonata.admin.configuration.templates', $config['templates']); + $container->setParameter('sonata.admin.configuration.default_admin_services', $config['default_admin_services']); + // NEXT_MAJOR: Remove this line. $container->setParameter('sonata.admin.configuration.admin_services', $config['admin_services']); $container->setParameter('sonata.admin.configuration.default_controller', $config['default_controller']); $container->setParameter('sonata.admin.configuration.dashboard_groups', $config['dashboard']['groups']); diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index d2c92c2abc2..551ff76995b 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -58,6 +58,11 @@ public function testOptionsWithInvalidFormat(): void ]]); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testCustomTemplatesPerAdmin(): void { $config = $this->process([[ @@ -75,6 +80,11 @@ public function testCustomTemplatesPerAdmin(): void $this->assertSame('@SonataAdmin/mycustomtemplate.html.twig', $config['admin_services']['my_admin_id']['templates']['view']['user_block']); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testAdminServicesDefault(): void { $config = $this->process([[ @@ -84,6 +94,7 @@ public function testAdminServicesDefault(): void $this->assertSame([ 'model_manager' => null, 'data_source' => null, + 'field_description_factory' => null, 'form_contractor' => null, 'show_builder' => null, 'list_builder' => null,