Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNP Menu Issue #205

Open
kussberg opened this issue Dec 1, 2017 · 5 comments
Open

KNP Menu Issue #205

kussberg opened this issue Dec 1, 2017 · 5 comments

Comments

@kussberg
Copy link

kussberg commented Dec 1, 2017

I have installed the latest master bundle and everything works ok, but the KNP Setup gives me:

The menu "avanzu_main" is not defined.

routing.yml

avanzu_admin_home:
  path: /
  defaults: {_controller: AppBundle:Default:index}
  options:
    avanzu_admin_route: welcome

services.yml

app.setup_knp_menu_listener:
        class: AppBundle\EventListener\SetupKnpMenuListener
        tags:
            - { name: kernel.event_listener, event: theme.sidebar_setup_knp_menu, method: onSetupMenu }

Admin Theme Configuration

avanzu_admin_theme:
    options:
        knp_menu:
            enable : true

AppBundle/EventListener/SetupKnpMenuListener.php

<?php
/**
 * Created by PhpStorm.
 * User: edgarkussberg
 * Date: 30.11.17
 * Time: 09:38
 */

namespace AppBundle\EventListener;

use Avanzu\AdminThemeBundle\Event\KnpMenuEvent;

class SetupKnpMenuListener
{
    public function onSetupMenu(KnpMenuEvent $event)
    {
        $menu = $event->getMenu();

        // Adds a menu item which acts as a label
        $menu->addChild('MainNavigationMenuItem', [
                'label' => 'MAIN NAVIGATION',
                'childOptions' => $event->getChildOptions()
            ]
        )->setAttribute('class', 'header');

        // A "regular" menu item with a link
        $menu->addChild('TestMenuItem', [
                'route' => 'homepage',
                'label' => 'Homepage',
                'childOptions' => $event->getChildOptions()
            ]
        )->setLabelAttribute('icon', 'fa fa-flag');

        // Adds a menu item which has children
        $menu->addChild('DataMenuItem', [
                'label' => 'Database mangement',
                'childOptions' => $event->getChildOptions()
            ]
        )->setLabelAttribute('icon', 'fa fa-database');
        // First child, a regular menu item
        $menu->getChild('DataMenuItem')->addChild('DataUsersMenuItem', [
                'route' => 'app.database.users',
                'label' => 'Users table',
                'childOptions' => $event->getChildOptions()
            ]
        )->setLabelAttribute('icon', 'fa fa-user');
        // Second child, a regular menu item
        $menu->getChild('DataMenuItem')->addChild('DataGroupsMenuItem', [
                'route' => 'app.database.groups',
                'label' => 'Groups table',
                'childOptions' => $event->getChildOptions()
            ]
        )->setLabelAttribute('icon', 'fa fa-users');
    }
}
@nikkiiworld
Copy link

I have the same issue. Did you solve this?

@ordermind
Copy link

ordermind commented Feb 23, 2018

The contents of /Resources/config/container/knp-menu.yml is not being read so the service is never registered. A workaround is to copy the contents of that file to your app's services.yml. Oh, and you probably need to add "public: true" to the service also.

@shakaran
Copy link
Collaborator

shakaran commented Feb 23, 2018

@ordermind there is not any knp-menu.yml file on this repo for 1.3.x version or master (aka future 2.x), also any on knp-menu repository, so I am not sure why you say that you need that file or recommend to others use that.

@shakaran shakaran added this to the Version 2.0 Stable milestone Feb 23, 2018
@Manalro
Copy link

Manalro commented Jul 26, 2018

I am using the dev-master version, yet I still have the same error. Is it normal ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants