Can/should there be a config switch to disable the built-in event listener service?
It's possible I'm a little confused about how event listeners should be used alongside the existing one. The service presta_sitemap.eventlistener.route_annotation
is already registered, and it seems if I follow the docs and create my own listener, this pre-existing one is still used.
For now I have been able to work around it by overriding the service class:
parameters:
presta_sitemap.eventlistener.route_annotation.class: Acme\MyBundle\EventListener\SitemapEventListener
However, I subsequently wanted to change the service definition (see PR #67) to inject the request_stack
service. If I make my own service definition, I'm back to the original problem - the built-in event listener still fires. I needed to create a compiler pass class (see the compiler pass docs).:
class SitemapCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('presta_sitemap.eventlistener.route_annotation')) {
$container
->getDefinition('presta_sitemap.eventlistener.route_annotation')
->addArgument(new Reference('request_stack'));
}
}
}
Alternatively, I could have used the compiler pass to remove the built-in service, making way for my own one. Either way, it's extra code in my project. ;)
So I'm wondering if there should be a config item 'event_listener_enabled' (default true) or similar?
If so, I don't mind doing a PR; I guess it's a case of dynamically creating that service in PrestaSitemapExtension
, or adding a compiler pass in your bundle to remove the service when a config switch says so (that way you get to keep the definition file route_annotation_listener.xml
where it's easier to see and modify).