1
votes

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!

2
The error is in cache file, did you clear all caches ?François Dupont
check if the service exist before try to remove itMatteo
@FrançoisDupont Yes I cleared the cache - no difference.Tim
@Matteo I just edited the process-method accordingly - no difference in the result. The service does exist and seems to be tried to access from somewhere else!Tim
Hi @Tim probably some other service is using it and is tring to accessing... try to look for same usage interally on the cmf source codeMatteo

2 Answers

1
votes

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

0
votes

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!