Permalink
Browse files

Merge in template changes from 3.0 branch

  • Loading branch information...
2 parents 496daf7 + 5c91469 commit 465444dc87322f7e88c145656b59c7958d35c34b @mlewis-everley mlewis-everley committed Nov 19, 2013
Showing with 62 additions and 54 deletions.
  1. +56 −48 code/extensions/CustomMenu.php
  2. +3 −3 code/extensions/CustomMenuExtension.php
  3. +3 −3 templates/Includes/CustomMenu.ss
@@ -1,52 +1,60 @@
<?php
class CustomMenu extends Extension {
- public function CustomMenu($menu = null) {
- if(isset($menu)) {
- // Ensure argument is safe for database
- $menu = Convert::raw2sql($menu);
-
- $filter = array(
- 'Slug' => $menu
- );
-
- // Add subsites support
- if(class_exists('Subsite') && $this->owner->CurrentSubsite())
- $filter['SubsiteID'] = $this->owner->CurrentSubsite()->ID;
-
- if($menu = CustomMenuHolder::get()->filter($filter)->first()) {
-
- if($menu->Order)
- $order = explode(',', $menu->Order);
-
- $pages = new ArrayList();
-
- if(isset($order) && is_array($order) && count($order) > 0) {
- foreach($order as $item) {
- $pages->push($menu->Pages()->find('ID',$item));
- }
- } else {
- foreach($menu->Pages() as $item) {
- $pages->push($item);
- }
- }
-
- if($pages->exists())
- return $pages;
- }
- } else
- return false;
- }
-
- public function RenderedCustomMenu($menu = null) {
- if(isset($menu)) {
- $vars = array(
- 'Slug' => $menu,
- 'Menu' => $this->owner->CustomMenu($menu)
+
+ /**
+ * Generate an list of items that will be loaded into the custom menu
+ *
+ * @param $menu template slug for retriving a menu
+ * @return ArrayList
+ */
+ public function CustomMenu($menu = "") {
+ $menu_items = new ArrayList();
+
+ if(isset($menu)) {
+ // Ensure argument is safe for database
+ $menu = Convert::raw2sql($menu);
+
+ $filter = array(
+ 'Slug' => $menu
);
-
- return $this->owner->renderWith('CustomMenu', $vars);
- } else
- return false;
-
- }
+
+ // Add subsites support
+ if(class_exists('Subsite') && $this->owner->CurrentSubsite())
+ $filter['SubsiteID'] = $this->owner->CurrentSubsite()->ID;
+
+ if($menu = CustomMenuHolder::get()->filter($filter)->first()) {
+
+ // If a custom order is set, use it
+ if($menu->Order)
+ $order = explode(',', $menu->Order);
+
+ if(isset($order) && is_array($order) && count($order) > 0) {
+ foreach($order as $item) {
+ $menu_items->push($menu->Pages()->find('ID',$item));
+ }
+ } else {
+ foreach($menu->Pages() as $item) {
+ $menu_items->push($item);
+ }
+ }
+ }
+ }
+
+ return $menu_items;
+ }
+
+ /**
+ * Take a list of custom menu items and render it into a template.
+ *
+ * @param $menu Template slug generated by the CMS
+ * @return string
+ */
+ public function RenderedCustomMenu($menu = "") {
+ $vars = array(
+ 'Slug' => $menu,
+ 'Menu' => $this->owner->CustomMenu($menu)
+ );
+
+ return $this->owner->renderWith('CustomMenu', $vars);
+ }
}
@@ -1,6 +1,6 @@
<?php
class CustomMenuExtension extends DataExtension {
- private static $belongs_many_many = array(
- 'CustomMenus' => 'CustomMenuHolder'
- );
+ private static $belongs_many_many = array(
+ 'CustomMenus' => 'CustomMenuHolder'
+ );
}
@@ -1,8 +1,8 @@
-<% if $Menu %>
+<% if $Menu.Exists %>
<ul class="menu-{$Slug}">
<% loop $Menu %>
- <li class="menu-{$Slug}-item $LinkingMode $FirstLast">
- <a class="menu-{$Slug}-link" href="$Link" title="$Title.XML">$MenuTitle.XML</a>
+ <li class="menu-{$Slug}-item $LinkingMode $FirstLast">
+ <a class="menu-{$Slug}-link" href="$Link" title="$Title.XML">$MenuTitle.XML</a>
</li>
<% end_loop %>
</ul>

0 comments on commit 465444d

Please sign in to comment.