mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Sort menu items according to priority descending, then title ascending
This commit is contained in:
parent
3457f43839
commit
b645703eb9
@ -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();
|
$menuPriority = array();
|
||||||
$i = 0;
|
$menuTitle = array();
|
||||||
foreach($menuItems as $key => $menuItem) {
|
foreach($menuItems as $key => $menuItem) {
|
||||||
$i++;
|
$menuPriority[$key] = $menuItem->priority;
|
||||||
// This funny litle formula ensures that the first item added with the same priority will be left-most.
|
$menuTitle[$key] = $menuItem->title;
|
||||||
$menuPriority[$key] = $menuItem->priority*100 - $i;
|
|
||||||
}
|
}
|
||||||
array_multisort($menuPriority, SORT_DESC, $menuItems);
|
array_multisort($menuPriority, SORT_DESC, $menuTitle, SORT_ASC, $menuItems);
|
||||||
|
|
||||||
return $menuItems;
|
return $menuItems;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,13 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
* @var array|string
|
* @var array|string
|
||||||
*/
|
*/
|
||||||
public static $managed_models = null;
|
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(
|
public static $allowed_actions = array(
|
||||||
'ImportForm',
|
'ImportForm',
|
||||||
|
Loading…
Reference in New Issue
Block a user