SonataUserBundle + FOSUserBundle - overriding controllers

3.1k Views Asked by At

I'm using SonataUserBundle with FOSUserBundle. in AppKernel.php it looks like this:

 new FOS\UserBundle\FOSUserBundle(),
 new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
 new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),

Some controllers from SonataUserBundle are already overriden.

Now I want to overridee FOSUserBundle ChangePasswordController. So I made: src/Application/FOS/UserBundle/Controller/ChangePasswordController.php src/Application/FOS/UserBundle/ApplicationFOSUserBundle.php

<?php
namespace Application\FOS\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ApplicationFOSUserBundle extends Bundle
{
    /**
    * {@inheritdoc}
    */
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

as well as modified AppKernel.php

 new FOS\UserBundle\FOSUserBundle(),
 new Application\FOS\UserBundle\FOSUserBundle(),
 new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
 new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),

The problem is... it's not working correctly.

Fatal error: Uncaught exception 'LogicException' with message 'Bundle "FOSUserBundle" is directly extended by two bundles "SonataUserBundle" and "ApplicationFOSUserBundle".' in /home/piotr.gawlowski/dev_dash_devel/dev-dash/app/bootstrap.php.cache on line 2364 ( ! ) LogicException: Bundle "FOSUserBundle" is directly extended by two bundles "SonataUserBundle" and "ApplicationFOSUserBundle". in /home/piotr.gawlowski/dev_dash_devel/dev-dash/app/bootstrap.php.cache on line 2364

1

There are 1 best solutions below

1
On

It is not possible to have two bundles extend the same bundle with bundle inheritance. The reason is simple ... how would symfony know which file to use if there was the same file in both extending bundles... Therefore bundle inheritance can only be linear.

This means in your case FOSUserBundle -> SonataUserBundle -> YourBundle.

Your bundle has to extend SonataUserBundle because SonataUserBundle already extends FOSUserBundle.

public function getParent()
{
    return 'SonataUserBundle';
}