Disable sonata.user.admin.group service from SonataUserBundle

I work with SonataAdminBundle and SonataUserBundle.

SonataUserBundle registers the sonata.user.admin.group service, which is automatically detected by SonataAdminBundle, to establish links in the admin control panel for grouping CRUD operations.

How to disable sonata.user.admin.group ? I follow these recipes in the Symfony2 documentation:

So far, I have the following code in my package definition to add a compiler pass:

 public function build(ContainerBuilder $container) { parent::build($container); $container->addCompilerPass(new CompilerPass()); } 

And here is the compiler pass:

 <?php namespace NS\Service\CompilerPass; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; class CompilerPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { $container->removeDefinition('sonata.user.admin.group'); } } 

I thought this should work, but no. Symfony throws an exception telling me that the sonata.user.admin.group service sonata.user.admin.group not exist. But it exists, and if I do $container->getDefinition('sonata.user.admin.group') , the actual definition is the return.

thanks

+4
source share
2 answers

Try marking the service as abstract and set its public property to false, for example.

 #in any services.yml services: sonata.user.admin.group: abstract: true public: false #... 

Addition to completeness:

And add to CompilerPass:

 $container->getDefinition('sonata.user.admin.group')->setSynthetic(true); 
+9
source

You have deleted the service definition, but it is still in use in the control panel. That's why Symfony is complaining (the dashboard is trying to access it). This is an optional service.

Can you try to overwrite the control panel template and not use this service? This method will not be called, and you do not have to delete it. If the service is not in use, it has never been created.

The alternative will overload the service with your implementation.

+1
source

All Articles