mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #1143 from svandragt/3.1
ENHANCEMENT Sort menu items according to priority descending, then title ascending
This commit is contained in:
commit
64b465f0cb
@ -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;
|
||||
}
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user