Tim
Tim

Reputation: 96

Symfony: Remove service (cmf_block.reference_admin)

I want to unregister the service cmf_block.reference_admin from Symfony. After some research I found out, that it should be done via CompilerPass. Here is how I removed it:

namespace PortalBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class UnregisterThirdPartyServicesPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if($container->getDefinition('cmf_block.reference_admin'))
            $container->removeDefinition('cmf_block.reference_admin');
    }
}

After having this done, I get an error:

Uncaught exception 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' with message 'You have requested a non-existent service "cmf_block.reference_admin".' in xxx\cmf-sandbox-master\app\bootstrap.php.cache:2198 Stack trace: #0 xxx\cmf-sandbox-master\app\cache\dev\classes.php(11818): Symfony\Component\DependencyInjection\Container->get('cmf_block.refer...') #1 xxx\cmf-sandbox-master\vendor\sonata-project\admin-bundle\Route\RoutesCacheWarmUp.php(47): Sonata\AdminBundle\Admin\Pool->getInstance('cmf_block.refer...') #2 xxx\cmf-sandbox-master\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate.php(48): Sonata\AdminBundle\Route\RoutesCacheWarmUp->warmUp('xxx') #3 xxx\cmf-sandbox-master\app\bootstrap.php.cache(2711): Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp('C:\ in xxx\cmf-sandbox-master\app\bootstrap.php.cache on line 2198

Maybe somebody of you can help me or knows, how it is possible to remove the Reference Block functionality of the CMF Block Bundle from my Symfony.

Thanks a lot in advance!

Upvotes: 1

Views: 1086

Answers (2)

Tim
Tim

Reputation: 96

Okay, I don't seem to be able to unregister this particular service. I think it's just too deep in 3rd party bundle.

My (very simple, not really making me happy) workaround now: Disallowing all routes to the service to every user, so it can't be accessed and removing the links from the dashboard.

Thanks for the help - if someone knows how to make the above work - I'll be always interested!

Upvotes: 0

Matteo
Matteo

Reputation: 39390

Check if the service exist before try to remove it, as example:

public function process(ContainerBuilder $container)
    {
        if ($container->hasDefinition('cmf_block.reference_admin'))
         {
           $container->removeDefinition('cmf_block.reference_admin');
         }
    }

And add your compiler pass in the moment that the service can really exist in the container. Check here how Controlling the Pass Ordering. As example, register as follow:

// ...
$container->addCompilerPass(
    new CustomPass(),
    PassConfig:: TYPE_REMOVE
);

Hope this help

Upvotes: 1

Related Questions