Sort menu items according to priority descending, then title ascending

This commit is contained in:
Sander van Dragt 2013-01-29 15:30:35 +00:00
parent 3457f43839
commit b645703eb9
2 changed files with 12 additions and 6 deletions

View File

@ -150,15 +150,14 @@ class CMSMenu extends Object implements IteratorAggregate, i18nEntityProvider
}
}
// Sort menu items according to priority
// Sort menu items according to priority, then title asc
$menuPriority = array();
$i = 0;
$menuTitle = array();
foreach($menuItems as $key => $menuItem) {
$i++;
// This funny litle formula ensures that the first item added with the same priority will be left-most.
$menuPriority[$key] = $menuItem->priority*100 - $i;
$menuPriority[$key] = $menuItem->priority;
$menuTitle[$key] = $menuItem->title;
}
array_multisort($menuPriority, SORT_DESC, $menuItems);
array_multisort($menuPriority, SORT_DESC, $menuTitle, SORT_ASC, $menuItems);
return $menuItems;
}

View File

@ -54,6 +54,13 @@ abstract class ModelAdmin extends LeftAndMain {
* @var array|string
*/
public static $managed_models = null;
/**
* Override menu_priority so that ModelAdmin CMSMenu objects
* are grouped together directly above the Help menu item.
* @var float
*/
public static $menu_priority = -0.5;
public static $allowed_actions = array(
'ImportForm',