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

Add a weight system to order items on the same branch #97

Closed
Maxwell2022 opened this issue Mar 11, 2013 · 7 comments
Closed

Add a weight system to order items on the same branch #97

Maxwell2022 opened this issue Mar 11, 2013 · 7 comments

Comments

@Maxwell2022
Copy link

It would be great to add an optional weight for the items of the menu. This weight would be used when rendering the menu to order the items located in the same level of the tree.

I know that at the moment if I want an item at the end of the list I have to add it last. But it would simplify a lot of logic in the code if we could use a weight system.

ie. you want to display 5 menu items depending of the user role:

without weight system:

$root->addChild('menu.item1', array('route' => '_my_route1'));
$root->addChild('menu.item2', array('route' => '_my_route2'));

if ($security->isGranted('ROLE_A')) {
   $root->addChild('menu.item3', array('route' => '_my_route3'));
}

$root->addChild('menu.item4', array('route' => '_my_route4'));

if ($security->isGranted('ROLE_A')) {
    $root->addChild('menu.item5', array('route' => '_my_route5'));
}

with a weight system:

$root->addChild('menu.item1', array('route' => '_my_route1', 'weight' => 0));
$root->addChild('menu.item2', array('route' => '_my_route2', 'weight' => 10));
$root->addChild('menu.item4', array('route' => '_my_route4', 'weight' => 20));

if ($security->isGranted('ROLE_A')) {
   $root->addChild('menu.item3', array('route' => '_my_route3', 'weight' => 15));
   $root->addChild('menu.item5', array('route' => '_my_route5', 'weight' => 25));
}

I had a look to the options and could not find it so I guess it's not been implemented for now but I'll be happy to know that I'm wrong :)

Cheers,
Maxime

@Maxwell2022
Copy link
Author

I'm guessing the tree is rendered recursively which mean we either need to sort the items before redering the branch or when we add the item in the menu directly. Any idea how it would be easier to manage this?

@asentner
Copy link

asentner commented Dec 9, 2014

+1. Would like to order when using listeners.

@Nek-
Copy link
Contributor

Nek- commented Dec 10, 2014

Oh and, actually i'm 👍 with this.

folliked pushed a commit to folliked/KnpMenu that referenced this issue Jun 15, 2015
folliked pushed a commit to folliked/KnpMenu that referenced this issue Jun 21, 2015
folliked pushed a commit to folliked/KnpMenu that referenced this issue Jun 21, 2015
folliked pushed a commit to folliked/KnpMenu that referenced this issue Jun 24, 2015
folliked added a commit to folliked/KnpMenu that referenced this issue Jun 24, 2015
@Nek- Nek- added this to the 2.1 milestone Jun 30, 2015
akerouanton pushed a commit that referenced this issue Jul 3, 2015
akerouanton pushed a commit that referenced this issue Jul 3, 2015
folliked added a commit to folliked/KnpMenu that referenced this issue Jul 16, 2015
folliked added a commit to folliked/KnpMenu that referenced this issue Jul 16, 2015
folliked added a commit to folliked/KnpMenu that referenced this issue Jul 17, 2015
@franzose
Copy link

Hi all! Any news on the issue?

@franzose
Copy link

SOLUTION

$item->reorderChildren([
    'child_name_1',
    'child_name_2',
    'child_name_3',
    'child_name_4',
]);

@Maxwell2022
Copy link
Author

Maxwell2022 commented Apr 13, 2017

I was looking for this for the last 4 years...

@franzose
Copy link

@Maxwell2022 I found that method occasionally) Array items are names you give to the menu's children.

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

4 participants