diff --git a/core/control/ContentController.php b/core/control/ContentController.php index 0c308feec..0a5c2d74f 100755 --- a/core/control/ContentController.php +++ b/core/control/ContentController.php @@ -320,30 +320,9 @@ JS if($this->dataRecord) { - $navItemClasses = ClassInfo::subclassesFor('SilverStripeNavigatorItem'); - array_shift($navItemClasses); - - // Sort menu items according to priority - $menuPriority = array(); - $i = 0; - foreach($navItemClasses as $navItemClass) { - if($navItemClass == 'SilverStripeNavigatorItem') continue; - - $i++; - $obj = new $navItemClass(); - // This funny litle formula ensures that the first item added with the same priority will be left-most. - $priority = Object::get_static($navItemClass, 'priority'); - $menuPriority[$priority * 100 - 1] = $obj; - } - ksort($menuPriority); - - foreach($menuPriority as $obj) { - - $text = $obj->getHTML($this->dataRecord); - if($text) $items .= $text; - $newMessage = $obj->getMessage($this); - if($newMessage) $message = $newMessage; - } + $return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord); + $items = $return['items']; + $message = $return['message']; } if($member) { diff --git a/core/control/SilverStripeNavigatorItem.php b/core/control/SilverStripeNavigatorItem.php index ba51a52b6..8568bc188 100644 --- a/core/control/SilverStripeNavigatorItem.php +++ b/core/control/SilverStripeNavigatorItem.php @@ -1,15 +1,66 @@ getHTML($record); + if($text) $items .= $text; + $newMessage = $obj->getMessage($record); + if($newMessage) $message = $newMessage; + } + + return array( + 'items' => $items, + 'message' => $message + ); + } +} /** * Navigator items are links that appear in the $SilverStripeNavigator bar. * To add an item, extends this class. + * + * @package cms + * @subpackage content */ class SilverStripeNavigatorItem extends Object { function getHTML($controller) {} function getMessage($controller) {} } +/** + * @package cms + * @subpackage content + */ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem { static $priority = 10; @@ -32,6 +83,10 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem { } +/** + * @package cms + * @subpackage content + */ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem { static $priority = 20; @@ -51,6 +106,10 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem { } } +/** + * @package cms + * @subpackage content + */ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem { static $priority = 30; @@ -70,6 +129,10 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem { } } +/** + * @package cms + * @subpackage content + */ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem { static $priority = 40; @@ -88,4 +151,4 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem { } } -?> +?> \ No newline at end of file diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index c15dcdcf1..532ec4cbb 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -1813,6 +1813,41 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid return $fields; } + function getNavigatorItems() { + $items = ''; + $message = ''; + + $navItemClasses = ClassInfo::subclassesFor('SilverStripeNavigatorItem'); + array_shift($navItemClasses); + + // Sort menu items according to priority + $menuPriority = array(); + $i = 0; + foreach($navItemClasses as $navItemClass) { + if($navItemClass == 'SilverStripeNavigatorItem') continue; + + $i++; + $obj = new $navItemClass(); + // This funny litle formula ensures that the first item added with the same priority will be left-most. + $priority = Object::get_static($navItemClass, 'priority'); + $menuPriority[$priority * 100 - 1] = $obj; + } + ksort($menuPriority); + + foreach($menuPriority as $obj) { + + $text = $obj->getHTML($this); + if($text) $items .= $text; + $newMessage = $obj->getMessage($this); + if($newMessage) $message = $newMessage; + } + + return array( + 'items' => $items, + 'message' => $message + ); + } + /** * * @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields