So, the problem with my fresh installation of Symfony 2.7.9 is that SonataUserBundle didn't update their dependencies and I'm stuck with a buggy bundle (I already tried to upgrade to a greater version without success).
Here's the error :
Attempted to call an undefined method named "setCurrentUri" of class "Knp\Menu\MenuItem".Did you mean to call "setCurrent"?
Which is thrown in the Sonata/Userbundle/Block/ProfileMenuBlockService.php at line 91
$menu->setCurrentUri($settings['current_uri']);
Therefore, I want to overload this file in my Application/Sonata/UserBundle but I don't understand why it won't work.
Here's what I did :
I copied the file responsible under Application/Sonata/UserBundle/Block/
<?php
namespace Application\Sonata\UserBundle\Block;
use Knp\Menu\ItemInterface;
use Knp\Menu\Provider\MenuProviderInterface;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\MenuBlockService;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\UserBundle\Menu\ProfileMenuBuilder;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Class ProfileMenuBlockService
*
* @package Sonata\UserBundle\Block
*
* @author Hugo Briand <briand@ekino.com>
*/
class ProfileMenuBlockService extends MenuBlockService
{
/**
* @var ProfileMenuBuilder
*/
private $menuBuilder;
/**
* Constructor
*
* @param string $name
* @param EngineInterface $templating
* @param MenuProviderInterface $menuProvider
* @param ProfileMenuBuilder $menuBuilder
*/
public function __construct($name, EngineInterface $templating, MenuProviderInterface $menuProvider, ProfileMenuBuilder $menuBuilder)
{
parent::__construct($name, $templating, $menuProvider, array());
$this->menuBuilder = $menuBuilder;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'User Profile Menu';
}
/**
* {@inheritdoc}
*/
public function setDefaultSettings(OptionsResolverInterface $resolver)
{
parent::setDefaultSettings($resolver);
$resolver->setDefaults(array(
'cache_policy' => 'private',
'menu_template' => "SonataBlockBundle:Block:block_side_menu_template.html.twig",
));
}
/**
* {@inheritdoc}
*/
protected function getMenu(BlockContextInterface $blockContext)
{
$settings = $blockContext->getSettings();
$menu = parent::getMenu($blockContext);
if (null === $menu || "" === $menu) {
$menu = $this->menuBuilder->createProfileMenu(
array(
'childrenAttributes' => array('class' => $settings['menu_class']),
'attributes' => array('class' => $settings['children_class']),
)
);
$menu->setCurrent($settings['current_uri']); // The corrected line
}
return $menu;
}
}
As it didn't worked, I also overloaded the configuration file Sonata/UserBundle/Resources/config/block.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.user.block.menu" class="Application\Sonata\UserBundle\Block\ProfileMenuBlockService">
<tag name="sonata.block" />
<argument>sonata.user.block.menu</argument>
<argument type="service" id="templating" />
<argument type="service" id="knp_menu.menu_provider" />
<argument type="service" id="sonata.user.profile.menu_builder" />
</service>
<service id="sonata.user.block.account" class="Sonata\UserBundle\Block\AccountBlockService">
<tag name="sonata.block" />
<argument>sonata.user.block.account</argument>
<argument type="service" id="templating" />
<argument type="service" id="security.context" />
</service>
</services>
</container>
Do you see anything that I am missing ?
Not to mention that I already cleared the cache and even rebooted my computer.
Thanks by advance.