Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/schema/menu-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</xsd:all>

<xsd:attribute name="templating" type="xsd:boolean" default="false"/>
<xsd:attribute name="route-voter" type="xsd:boolean" default="true"/>
<xsd:attribute name="default-renderer" type="xsd:string" default="twig"/>
</xsd:complexType>

Expand Down
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -78,10 +80,12 @@ You can define these options if you need to change them:

<!--
templating: if true, enable the helper for PHP templates (deprecated)
route-voter: set to false to not register the default RouteVoter
default-renderer: the renderer to use, list is also available by default
-->
<knp-menu:config
templating="false"
route-voter="true"
default-renderer="twig"
>
<!-- add enabled="false" to disable the Twig extension and the TwigRenderer -->
Expand All @@ -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',
]);
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/KnpMenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function getConfigs(): array
return [
['<config xmlns="http://knplabs.com/schema/dic/menu"/>'],
[<<<EOC
<config xmlns="http://knplabs.com/schema/dic/menu" templating="true" default-renderer="templating">
<config xmlns="http://knplabs.com/schema/dic/menu" templating="true" route-voter="false" default-renderer="templating">
<providers builder-alias="false" container-aware="false" builder-service="false"/>
<twig template="custom.html.twig"/>
</config>
Expand Down
9 changes: 9 additions & 0 deletions tests/DependencyInjection/KnpMenuExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading