Waiting for Dev...
Waiting for Dev...

Reputation: 13037

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:

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

Upvotes: 4

Views: 3497

Answers (2)

Mun Mun Das
Mun Mun Das

Reputation: 15002

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);

Upvotes: 9

Jakub Zalas
Jakub Zalas

Reputation: 36241

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.

Upvotes: 1

Related Questions