diff --git a/README.md b/README.md
index c6359a7..e6f040c 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,14 @@ MenuSet:
- Footer
```
+### Allow sorting of MenuSets
+
+By default menu sets cannot be sorted, however, you can set your configuration to allow it.
+
+```yaml
+MenuSet:
+ allow_sorting: true
+```
### Creating MenuItems
@@ -83,10 +91,29 @@ Can be used as a check to see if 'target="_blank"' should be added to links.
### Usage in template
+To loop through a specific MenuSet's items:
+
<% loop $MenuSet('YourMenuName').MenuItems %>
$MenuTitle
<% end_loop %>
+To loop through *all* MenuSets and their items:
+
+ <% loop $MenuSets %>
+ <% loop $MenuItems %>
+ $MenuTitle
+ <% end_loop %>
+ <% end_loop %>
+
+Optionally you can also limit the number of MenuSets and MenuItems that are looped through.
+
+The example below will fetch the top 4 MenuSets (as seen in Menu Management), and the top 5 MenuItems for each:
+
+ <% loop $MenuSets.Limit(4) %>
+ <% loop $MenuItems.Limit(5) %>
+ $MenuTitle
+ <% end_loop %>
+ <% end_loop %>
###Code guidelines
diff --git a/code/MenuAdmin.php b/code/MenuAdmin.php
index 55476b1..33867ce 100644
--- a/code/MenuAdmin.php
+++ b/code/MenuAdmin.php
@@ -26,4 +26,22 @@ class MenuAdmin extends ModelAdmin
* @var array
*/
private static $model_importers = array();
+
+ /**
+ * @param mixed $id
+ * @param mixed $fields
+ * @return ModelAdmin
+ */
+ public function getEditForm($id = null, $fields = null) {
+ $form = parent::getEditForm($id, $fields);
+
+ if (Config::inst()->get($this->modelClass, 'allow_sorting')) {
+ $gridFieldName = $this->sanitiseClassName($this->modelClass);
+ $gridField = $form->Fields()->fieldByName($gridFieldName);
+
+ $gridField->getConfig()->addComponent(new GridFieldOrderableRows());
+ }
+
+ return $form;
+ }
}
diff --git a/code/MenuManagerTemplateProvider.php b/code/MenuManagerTemplateProvider.php
index 1c46876..3026478 100644
--- a/code/MenuManagerTemplateProvider.php
+++ b/code/MenuManagerTemplateProvider.php
@@ -8,7 +8,8 @@ class MenuManagerTemplateProvider implements TemplateGlobalProvider
public static function get_template_global_variables()
{
return array(
- 'MenuSet' => 'MenuSet'
+ 'MenuSet' => 'MenuSet',
+ 'MenuSets' => 'MenuSets'
);
}
@@ -25,4 +26,12 @@ public static function MenuSet($name)
)
)->first();
}
-}
\ No newline at end of file
+
+ /**
+ * @return DataList
+ */
+ public static function MenuSets()
+ {
+ return MenuSet::get();
+ }
+}
diff --git a/code/MenuSet.php b/code/MenuSet.php
index 2d25605..621fa6e 100644
--- a/code/MenuSet.php
+++ b/code/MenuSet.php
@@ -9,7 +9,8 @@ class MenuSet extends DataObject implements PermissionProvider
* @var array
*/
private static $db = array(
- 'Name' => 'Varchar(255)'
+ 'Name' => 'Varchar(255)',
+ 'Sort' => 'Int'
);
/**
@@ -43,6 +44,11 @@ public function providePermissions()
);
}
+ /**
+ * @var string
+ */
+ private static $default_sort = 'Sort';
+
/**
* @param mixed $member
* @return boolean