mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
APICHANGE: Use the same navigator items in the CMS that are used on the frontend (from r97395)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99079 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
483fd06037
commit
ed8e75ea8d
@ -320,30 +320,9 @@ JS
|
|||||||
|
|
||||||
|
|
||||||
if($this->dataRecord) {
|
if($this->dataRecord) {
|
||||||
$navItemClasses = ClassInfo::subclassesFor('SilverStripeNavigatorItem');
|
$return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord);
|
||||||
array_shift($navItemClasses);
|
$items = $return['items'];
|
||||||
|
$message = $return['message'];
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($member) {
|
if($member) {
|
||||||
|
@ -1,15 +1,66 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* @package cms
|
||||||
|
* @subpackage content
|
||||||
|
*/
|
||||||
|
class SilverStripeNavigator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SiteTree $record
|
||||||
|
* @return Array template data
|
||||||
|
*/
|
||||||
|
static function get_for_record($record) {
|
||||||
|
$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($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.
|
* Navigator items are links that appear in the $SilverStripeNavigator bar.
|
||||||
* To add an item, extends this class.
|
* To add an item, extends this class.
|
||||||
|
*
|
||||||
|
* @package cms
|
||||||
|
* @subpackage content
|
||||||
*/
|
*/
|
||||||
class SilverStripeNavigatorItem extends Object {
|
class SilverStripeNavigatorItem extends Object {
|
||||||
function getHTML($controller) {}
|
function getHTML($controller) {}
|
||||||
function getMessage($controller) {}
|
function getMessage($controller) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package cms
|
||||||
|
* @subpackage content
|
||||||
|
*/
|
||||||
class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem {
|
class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem {
|
||||||
static $priority = 10;
|
static $priority = 10;
|
||||||
|
|
||||||
@ -32,6 +83,10 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package cms
|
||||||
|
* @subpackage content
|
||||||
|
*/
|
||||||
class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
|
class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
|
||||||
static $priority = 20;
|
static $priority = 20;
|
||||||
|
|
||||||
@ -51,6 +106,10 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package cms
|
||||||
|
* @subpackage content
|
||||||
|
*/
|
||||||
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
|
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
|
||||||
static $priority = 30;
|
static $priority = 30;
|
||||||
|
|
||||||
@ -70,6 +129,10 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package cms
|
||||||
|
* @subpackage content
|
||||||
|
*/
|
||||||
class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
|
class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
|
||||||
static $priority = 40;
|
static $priority = 40;
|
||||||
|
|
||||||
@ -88,4 +151,4 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -1813,6 +1813,41 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
return $fields;
|
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
|
* @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields
|
||||||
|
Loading…
Reference in New Issue
Block a user