1
votes

Im trying to use the following two bundles in my symfony2.1 project:

My problem is, the two bundles use both knp-menu bundle. But sonata needs 1.1.x-dev of knp-menu bundle and braincrafted bootstrap-bundle dev-master.

With the following composer settings i get the following error. Composer.json:

    "sonata-project/admin-bundle": "dev-master",
    "sonata-project/doctrine-orm-admin-bundle": "dev-master",
    "sonata-project/intl-bundle": "dev-master",
    "sonata-project/cache-bundle": "dev-master",
    "knplabs/knp-menu-bundle": "1.1.x-dev",
    "braincrafted/bootstrap-bundle": "dev-develop"

Error: Knp\Menu\Matcher\Voter\VoterInterface' not found in vendor/braincrafted/bootstrap-bundle/Braincrafted/BootstrapBundle/Voter/RequestVoter

I know that the Matcher doesn't exist in the early knp menu bundle version. But if i change the knp menu bundle version to:

"knplabs/knp-menu-bundle": "dev-master",

it isn't possible to install the sonata admin bundle. The following error occurs if i execute the command "composer.phar update"

  Problem 1
    - sonata-project/admin-bundle dev-master requires knplabs/knp-menu-bundle >=1.1.0,<2.0.x-dev -> satisfiable by knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle v1.1.0.
    - sonata-project/admin-bundle dev-master requires knplabs/knp-menu-bundle >=1.1.0,<2.0.x-dev -> satisfiable by knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle v1.1.0.
    - Can only install one of: knplabs/knp-menu-bundle dev-master, knplabs/knp-menu-bundle 1.1.x-dev.
    - Can only install one of: knplabs/knp-menu-bundle dev-master, knplabs/knp-menu-bundle 1.1.x-dev.
    - Can only install one of: knplabs/knp-menu-bundle v1.1.0, knplabs/knp-menu-bundle dev-master.
    - Installation request for knplabs/knp-menu-bundle dev-master -> satisfiable by knplabs/knp-menu-bundle dev-master.
    - Installation request for sonata-project/admin-bundle dev-master -> satisfiable by sonata-project/admin-bundle dev-master.

Has someone an idea how can i use both bundles or isn't there a way? Thanks for help.

3
Did you open a ticket for this? - Mick
no, but a ticket with this problem is already open - Flow

3 Answers

1
votes

Edit composer.json and modify the line with reference to knp-menu-bundle to look like this: "knplabs/knp-menu-bundle": "1.1.x-dev",

It needs a version >=1.1.0,<2.0.x-dev which is stated in the first line of the error.

That works for me.

0
votes

Using the Composer you cannot use both bundles. Actually you should open a ticket in the https://github.com/braincrafted/bootstrap-bundle and explain the situation. They should update the composer.json of the project to allow people to use the current version of KnpMenu and not only the most recent version.

0
votes

I found a temporary solution to use both bundles until this ticket is resolved.

I defined a repository in my composer.json file and manipulated the sonata admin bundle requirements ("knplabs/knp-menu-bundle": "dev-master"):

"repositories": [
{
    "type": "package",             
    "package": {
        "name": "sonata-project/admin-bundle",
        "type": "symfony-bundle",
        "description": "Symfony SonataAdminBundle",
        "keywords": ["Admin Generator", "admin", "sonata", "bootstrap"],
        "homepage": "http://sonata-project.org/bundles/admin",
        "license": "MIT",
        "authors": [
        {
            "name": "Thomas Rabaix",
            "email": "[email protected]",
            "homepage": "http://sonata-project.org"
        },
        {
            "name": "Sonata Community",
            "homepage": "https://github.com/sonata-project/SonataAdminBundle/contributors"
        }
        ],
        "require": {
            "symfony/http-foundation": ">=2.1,<2.3-dev",
            "symfony/form": ">=2.1,<2.3-dev",
            "symfony/validator": ">=2.1,<2.3-dev",
            "symfony/security-bundle": ">=2.1,<2.3-dev",
            "symfony/routing": ">=2.1,<2.3-dev",
            "symfony/config": ">=2.1,<2.3-dev",
            "symfony/console": ">=2.1,<2.3-dev",
            "symfony/twig-bridge": ">=2.1,<2.3-dev",
            "twig/twig": ">=1.10,<2.0-dev",
            "knplabs/knp-menu-bundle": "dev-master",
            "sonata-project/jquery-bundle": "dev-master",
            "sonata-project/exporter": "dev-master",
            "sonata-project/block-bundle": "dev-master",
            "doctrine/common": ">=2.2,<3.0"
        },
        "require-dev": {
            "jms/translation-bundle": "*"
        },
        "suggest": {
            "sonata-project/doctrine-orm-admin-bundle": "dev-master",
            "sonata-project/intl-bundle": "dev-master"
        },
        "autoload": {
            "psr-0": {
                "Sonata\\AdminBundle": ""
            }
        },
        "target-dir": "Sonata/AdminBundle",            
        "version": "dev-master",
        "source": {
            "url": "git://github.com/sonata-project/SonataAdminBundle.git",
            "type": "git",
            "reference": "0269691d61764798537a2fd3b13bfafbfb387eef"
        }                   

    }
}

Then i had to overwrite the method buildSideMenu in the admin class, because the method setCurrentUri() doesn't exist anymore (is now named setUri()). And all my own admin classes extend now MyAdmin

abstract class MyAdmin extends Admin
{

    /**
     * Build the side menu related to the current action
     *
     * @param string                                   $action
     * @param \Sonata\AdminBundle\Admin\AdminInterface $childAdmin
     *
     * @return \Knp\Menu\ItemInterface|boolean
     */
    public function buildSideMenu($action, AdminInterface $childAdmin = null)
    {
        if ($this->loaded['side_menu']) {
            return;
        }

        $this->loaded['side_menu'] = true;

        $menu = $this->menuFactory->createItem('root');
        $menu->setChildrenAttribute('class', 'nav nav-list');
        $menu->setUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo());

        $this->configureSideMenu($menu, $action, $childAdmin);

        foreach ($this->getExtensions() as $extension) {
            $extension->configureSideMenu($this, $menu, $action, $childAdmin);
        }

        $this->menu = $menu;
    }


}

I know this isn't the best solution but it worked for my purpose