Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable SonataUserBundle sonata.user.admin.group service

I'm working with SonataAdminBundle and SonataUserBundle.

SonataUserBundle registers a service sonata.user.admin.group which is automatically detected by SonataAdminBundle to set links in the admin dashboard to group CRUD operations.

How can I disable sonata.user.admin.group? I've been following that recipes in Symfony2 documentation:

  • How to Override any Part of a Bundle - Services and Configuration

  • Compiling the Container - Creating a Compiler Pass

  • Working with Container Parameters and Definitions

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

public function build(ContainerBuilder $container)
{
  parent::build($container);

  $container->addCompilerPass(new CompilerPass());
}

And here it 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 that this should work but no. Symfony is throwing an exception telling me that sonata.user.admin.group service does not exist. But it exists, and if I do $container->getDefinition('sonata.user.admin.group') the actual definition is return.

Thanks

like image 774
Waiting for Dev... Avatar asked Dec 27 '22 12:12

Waiting for Dev...


2 Answers

Try marking the service as abstract and set its public property to false e.g.

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

Addition to completeness:

And add to the CompilerPass:

$container->getDefinition('sonata.user.admin.group')->setSynthetic(true);
like image 62
Mun Mun Das Avatar answered Dec 30 '22 10:12

Mun Mun Das


You've removed the service definition but it's still used on the dashboard. That's why Symfony complains (dashboard tries to access it). It's not an optional service.

You could try to overwrite the dashboard template and avoid using the service? This way service wouldn't be called and you wouldn't have to remove it. If service is not used it's never created.

Alternative would be overloading the service with your implementation.

like image 37
Jakub Zalas Avatar answered Dec 30 '22 10:12

Jakub Zalas