avanzu / AdminThemeBundle

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

KNP menu enabled true not working #184

Open glerendegui opened 7 years ago

glerendegui commented 7 years ago

I'm having a problem with knp_menu. My config is

avanzu_admin_theme:
    knp_menu:                         # knp menu integration     
        enable         : true 

but when I put {{ dump(avanzu_admin_context.knp_menu) }} on default-layout.html.twig it dumps

array:3 [▼
  "enable" => false
  "main_menu" => "AvanzuAdminThemeBundle:MenuBuilder:createMainMenu"
  "breadcrumb_menu" => false
]

So, knp is never activated.

Also, (maybe this should go on another thread) if I change

enable

default option at ContexHelper.php to true I get

Unknown "knp_menu_render" function at

knp-menu.html.twig at line 2 (knp_menu_render(avanzu_admin_context.knp_menu.main_menu, {)

Maybe I need to install knp bundle?

shakaran commented 7 years ago

It seems that the docs needs to be updated to be more clear.

https://github.com/avanzu/AdminThemeBundle/blob/master/Resources/docs/knp_menu.md

Since the use of knp is optional, the package is not installed and "suggested", but I think that it is not detected at any place which is missing when you enable, so you get the ugly error/warning instead a useful message that says that you need install knpmenu

So you need first install with composer:

composer require knplabs/knp-menu-bundle

And you have 2 places where enable.

First it is using in general, which is under:

avanzu_admin_theme:
    knp_menu:                         # knp menu integration     
        enable: true 

But if you use the avanzu_admin_context, it requires enable in the context, which is under the "options" key, that is:

avanzu_admin_theme:
    options:
        knp_menu:                         # knp menu integration     
            enable: true 

So two task to me here:

hounded commented 6 years ago

So i'm updating and have built my menu using

avanzu_admin_theme:
    knp_menu:                         # knp menu integration
        enable         : true

and using a service

services:
    orders.knp_menu_listener:
        class: AppBundle\EventListener\ordersKnpMenuListener
        arguments: ['@service_container']
        tags:
            - { name: kernel.event_listener, event: theme.sidebar_setup_knp_menu, method: onSetupKnpMenu}

so this use to work with beta5 but on beta10 this doesn't work no more I still get the same as original question if I dump out knp_menu

array:3 [▼
  "enable" => false
  "main_menu" => "avanzu_main"
  "breadcrumb_menu" => false
]

How can I resolve it so my already created and working menu works?

hounded commented 6 years ago

Ok the following service is not getting picked up, adding it to my services resolved the problem.

    avanzu_admin_theme.knp_menu_builder:
        class: "%avanzu_admin_theme.knp_menu_builder.class%"
        arguments:
            - "@knp_menu.factory"
            - "@avanzu_admin_theme.admin_router"
            - "@event_dispatcher"
        tags:
            - {name: knp_menu.menu_builder, method: createMainMenu, alias: avanzu_main }