caffeinated / menus

:pushpin: Menu generator package for the Laravel framework
https://caffeinatedpackages.com
132 stars 59 forks source link

edge issue: mutliple module menu ordering #13

Closed illuminate3 closed 9 years ago

illuminate3 commented 9 years ago

Well, probably not that much of and edge issue if combined with your module package.

In my main MenuServiceProvider I have:

// navbar menu
        Menu::make('navbar', function($menu) {
            //
        });

Then in a module I have:

// navbar menu
        $menu = Menu::get('navbar');
        $menu->add('Profiles', 'profiles');

This works for multiple modules.

However the issue I'm having is with trying to get a module menu to over ride the module ordering ... I haven't checked but I'm guess is that the module order is what sets the default for the menus.

I tried: in my main MenuServiceProvider:

// navbar menu
        Menu::make('navbar', function($menu) {
            //
        })->sortBy('order');

Then in the module menu provider:

// navbar menu
        $menu = Menu::get('navbar');
        $menu->add('Profiles', 'profiles')->data('order', 0); // tried with 1 too

But another module that has a higher order rank is still being placed first.

I probably just send all this to a db table and create them there but I'm still working on understanding.

kaidesu commented 9 years ago

Simply call sortBy every time you modify or add on to your menus so the items get re-ordered properly.

illuminate3 commented 9 years ago

I thought that would be on the main Menu:make. Should I be adding that after the ->data(order)?

kaidesu commented 9 years ago

You only need to call it once, per menu modification:

Initial Menu Creation:

Menu::make('navbar', function($menu) {
    ...
})->sortBy('order');

Module's Menu Modification:

$menu = Menu::get('navbar');
$menu->add('Profiles', 'profiles')->data('order', 0);
$menu->sortBy('order');  // Will re-order all menu items for the 'navbar' menu
illuminate3 commented 9 years ago

Thanks!