diff --git a/config/schema/menu-1.0.xsd b/config/schema/menu-1.0.xsd index a9cb484f..5a8f3694 100644 --- a/config/schema/menu-1.0.xsd +++ b/config/schema/menu-1.0.xsd @@ -14,6 +14,7 @@ + diff --git a/docs/index.rst b/docs/index.rst index 693a270e..de7001bb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,6 +66,8 @@ You can define these options if you need to change them: # if true, enables the helper for PHP templates # support for templating is deprecated, it will be removed in next major version templating: false + # set to false to not register the default RouteVoter + route_voter: true # the renderer to use, list is also available by default default_renderer: twig @@ -78,10 +80,12 @@ You can define these options if you need to change them: @@ -99,6 +103,8 @@ You can define these options if you need to change them: ], // if true, enable the helper for PHP templates (deprecated) 'templating' => false, + // set to false to not register the default RouteVoter + 'route_voter' => true, // the renderer to use, list is also available by default 'default_renderer' => 'twig', ]); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7282f528..3bdf88a2 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -37,6 +37,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->booleanNode('templating')->defaultFalse()->end() + ->booleanNode('route_voter')->defaultTrue()->end() ->scalarNode('default_renderer')->cannotBeEmpty()->defaultValue('twig')->end() ->end(); diff --git a/src/DependencyInjection/KnpMenuExtension.php b/src/DependencyInjection/KnpMenuExtension.php index ca752dc9..50a9e264 100644 --- a/src/DependencyInjection/KnpMenuExtension.php +++ b/src/DependencyInjection/KnpMenuExtension.php @@ -38,6 +38,10 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('templating.php'); } + if (!$config['route_voter']) { + $container->removeDefinition('knp_menu.voter.router'); + } + $container->setParameter('knp_menu.default_renderer', $config['default_renderer']); $container->registerForAutoconfiguration(VoterInterface::class) diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index eccaf88b..28ca6770 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -30,7 +30,7 @@ public static function getConfigs(): array return [ [''], [<< + diff --git a/tests/DependencyInjection/KnpMenuExtensionTest.php b/tests/DependencyInjection/KnpMenuExtensionTest.php index e135004a..142ec5a5 100644 --- a/tests/DependencyInjection/KnpMenuExtensionTest.php +++ b/tests/DependencyInjection/KnpMenuExtensionTest.php @@ -19,6 +19,15 @@ public function testDefault(): void $this->assertEquals('@KnpMenu/menu.html.twig', $container->getParameter('knp_menu.renderer.twig.template')); $this->assertFalse($container->hasDefinition('knp_menu.templating.helper'), 'The PHP helper is not loaded'); $this->assertTrue($container->getDefinition('knp_menu.menu_provider.builder_alias')->hasTag('knp_menu.provider'), 'The BuilderAliasProvider is enabled'); + $this->assertTrue($container->hasDefinition('knp_menu.voter.router'), 'The default RouteVoter is registered'); + } + + public function testDisableRouteVoter(): void + { + $container = new ContainerBuilder(); + $loader = new KnpMenuExtension(); + $loader->load([['route_voter' => false]], $container); + $this->assertFalse($container->hasDefinition('knp_menu.voter.router'), 'The default RouteVoter is not registered'); } public function testEnableTwig(): void