Skip to content

Commit

Permalink
FEATURE, adding a flag so you may sort your grouped CMS menu alphabet…
Browse files Browse the repository at this point in the history
…ically.
  • Loading branch information
Nathan Glasl committed Jan 11, 2017
1 parent 0066563 commit 12bed02
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ LeftAndMain:
- AssetAdmin
```
When you have larger menus, and/or multiple modules combining to the same menu, this may require something more consistent. In which case, you may sort your grouped menus alphabetically.
```yml
LeftAndMain:
menu_groups:
CMSPagesController:
- CMSPagesController
Other:
- ReportAdmin
- AssetAdmin
menu_groups_alphabetical_sorting: true
```
## Group icons
You can add a CSS class to groups for the purpose of adding an icon. The class name will be prefixed with 'icon-'.
Expand Down
11 changes: 9 additions & 2 deletions code/GroupedCmsMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class GroupedCmsMenu extends Extension {
*/
private static $menu_groups = array();

/**
* When you have larger menus, and/or multiple modules combining to the same menu, this may require something more consistent.
*/

private static $menu_groups_alphabetical_sorting = false;

/**
* Require in CSS which we need for the menu
*/
Expand All @@ -24,7 +30,8 @@ public function init() {
public function GroupedMainMenu() {
$items = $this->owner->MainMenu();
$result = ArrayList::create();
$groupSettings = Config::inst()->get('LeftAndMain', 'menu_groups');
$config = Config::inst();
$groupSettings = $config->get('LeftAndMain', 'menu_groups');
$itemsToGroup = array();
$groupSort = 0;
$itemSort = 0;
Expand Down Expand Up @@ -71,7 +78,7 @@ public function GroupedMainMenu() {
'Link' => $children->First()->Link,
'Icon' => $icon,
'LinkingMode' => $active ? 'current' : '',
'Children' => $children->sort('SortOrder')
'Children' => $config->get('LeftAndMain', 'menu_groups_alphabetical_sorting') ? $children->sort('Title') : $children->sort('SortOrder')
)));
} else {
$result->push($children->First());
Expand Down

0 comments on commit 12bed02

Please sign in to comment.