avanzu / AdminThemeBundle

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

How to achieve multilevel menus? #239

Open xmontero opened 6 years ago

xmontero commented 6 years ago

In the AdminLte demo here https://adminlte.io/themes/AdminLTE/index2.html I can see multilevel menus.

Instead, when I try to do them in avanzu, I can't display them:

If I do this (only 1 level):

$level1 = new MenuItemModel( 'level1', 'Level 1', 'form_submission_bulk_display_change_state_form', [], 'fa fa-star' );

$menuItems[ 'tests' ]->addChild( $level1 );

I get this:

image

If I do this (2 levels), I'd expect that the menu "Level 1" contains a caret to open a submenu named "Level 2".

$level1 = new MenuItemModel( 'level1', 'Level 1', 'form_submission_bulk_display_change_state_form', [], 'fa fa-star' );
$level2 = new MenuItemModel( 'level2', 'Level 2', 'form_submission_bulk_display_change_state_form', [], 'fa fa-star' );
$level1->addChild( $level2 );

$menuItems[ 'tests' ]->addChild( $level1 );

Instead, I get this:

image

And there's no toggle there to open/close, as it'd be expected according to the AdminLte demo:

image

Question: How can I code submenus in a multilevel menu?

Component Version
Symfony version Symfony 3.3.10
AdminThemeBundle 1.3.10
Operating System Ubuntu 16.04 LTS
xmontero commented 6 years ago

Will this be also available in 1.3?

shakaran commented 6 years ago

@xmontero do you need it? Maybe it could be backported. But the idea is get rid soon of 1.3.x series and use as soon as possible 2.x and 3.x in future

xmontero commented 6 years ago

Well, I guess that changing the major means it breaks compatibility. I have a huge dependency on the bundle and I'm not ready to afford the resources to "migrate from 1.3 to 2.0" if it is "very different" to consume.

Breaking my admin panel say during 1 week could kill my business.

Is there any documentation on "migrating from 1.3 to 2.0". If it's "easy" I can try to move to 2.0.

As an example, large projects migrating from symfony 1 to 2 took 1 to 2 years of rewriting, while porting from symfony 2 to 3 was a matter of changing some directories and done. With this, I mean it's very "unpredictable" how much time it'll take to tackle a major-version change, unless it's clear where to touch. Symfony has had this in consideration and made any other "major" migration much simpler. Passing from 3 to 4 seems "trivial".

What's the complexity of moving avanzu from 1.3 to 2.0? Any documentation on that?

danielroehrig-mm commented 6 years ago

@xmontero I implemented the feature by overwriting the macros.html.twigfile. It's been a while and I'm not sure if this is the right way of doing this but here you go Just copy the macros.html.twigfile into app/Resources/AvanzuAdminThemeBundle/views/layout/macros.html.twig and replace the menu_itemmacro. Hope this helps.

shakaran commented 2 years ago

@xmontero please confirm if this is working for you:

// Declare a empty array
$menuItems = [];

// Declare the MenuItemModels
$level1 = new MenuItemModel( 'level1', 'Level 1', 'form_submission_bulk_display_change_state_form', [], 'fa fa-star' );
$level2 = new MenuItemModel( 'level2', 'Level 2', 'form_submission_bulk_display_change_state_form', [], 'fa fa-star' );

// Add the child
$level1->addChild( $level2 );

// Add as item in menu.
$menuItems = [$level1];

Check that you don't have duplicated identifiers (there are a bug with collision name identifiers)