avanzu / AdminThemeBundle

Admin Theme based on the AdminLTE Template for easy integration into symfony
MIT License
281 stars 149 forks source link

KNP Menu Issue #205

Open kussberg opened 6 years ago

kussberg commented 6 years ago

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 commented 6 years ago

I have the same issue. Did you solve this?

ordermind commented 6 years ago

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 commented 6 years ago

@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.

ordermind commented 6 years ago

https://github.com/avanzu/AdminThemeBundle/blob/master/Resources/config/container/knp-menu.yml

Manalro commented 5 years ago

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