mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FEATURE: Refactor links in $SilverStripeNavigator so modules can add extras (from r97299)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99046 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3d6baa81d5
commit
1f60bde524
@ -293,6 +293,8 @@ class ContentController extends Controller {
|
||||
|
||||
public function SilverStripeNavigator() {
|
||||
$member = Member::currentUser();
|
||||
$items = '';
|
||||
$message = '';
|
||||
|
||||
if(Director::isDev() || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
|
||||
Requirements::css(SAPPHIRE_DIR . '/css/SilverStripeNavigator.css');
|
||||
@ -314,55 +316,44 @@ class ContentController extends Controller {
|
||||
})(jQuery);
|
||||
JS
|
||||
);
|
||||
|
||||
|
||||
if($this->dataRecord){
|
||||
$thisPage = $this->dataRecord->Link();
|
||||
$cmsLink = 'admin/show/' . $this->dataRecord->ID;
|
||||
$cmsLink = "<a href=\"$cmsLink\" target=\"cms\">". _t('ContentController.CMS', 'CMS') ."</a>";
|
||||
} else {
|
||||
/**
|
||||
* HGS: If this variable is missing a notice is raised. Subclasses of ContentController
|
||||
* are required to implement RelativeLink anyway, so this should work even if the
|
||||
* dataRecord isn't set.
|
||||
*/
|
||||
$thisPage = $this->Link();
|
||||
$cmsLink = '';
|
||||
}
|
||||
|
||||
$archiveLink = "";
|
||||
|
||||
if($date = Versioned::current_archived_date()) {
|
||||
$dateObj = Object::create('Datetime', $date, null);
|
||||
// $dateObj->setVal($date);
|
||||
|
||||
$archiveLink = "<a class=\"current\">". _t('ContentController.ARCHIVEDSITE', 'Archived Site') ."</a>";
|
||||
$liveLink = "<a href=\"$thisPage?stage=Live\" target=\"site\" style=\"left : -3px;\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</a>";
|
||||
$stageLink = "<a href=\"$thisPage?stage=Stage\" target=\"site\" style=\"left : -1px;\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</a>";
|
||||
$message = "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.ARCHIVEDSITEFROM', 'Archived site from') ."<br>" . $dateObj->Nice() . "</div>";
|
||||
|
||||
} else if(Versioned::current_stage() == 'Stage') {
|
||||
$stageLink = "<a class=\"current\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</a>";
|
||||
$liveLink = "<a href=\"$thisPage?stage=Live\" target=\"site\" style=\"left : -3px;\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</a>";
|
||||
$message = "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</div>";
|
||||
|
||||
} else {
|
||||
$liveLink = "<a class=\"current\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</a>";
|
||||
$stageLink = "<a href=\"$thisPage?stage=Stage\" target=\"site\" style=\"left : -1px;\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</a>";
|
||||
$message = "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</div>";
|
||||
|
||||
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;
|
||||
if(!$message) $message = $obj->getMessage($this);
|
||||
}
|
||||
}
|
||||
|
||||
if($member) {
|
||||
$firstname = Convert::raw2xml($member->FirstName);
|
||||
$surname = Convert::raw2xml($member->Surame);
|
||||
$surname = Convert::raw2xml($member->Surname);
|
||||
$logInMessage = _t('ContentController.LOGGEDINAS', 'Logged in as') ." {$firstname} {$surname} - <a href=\"Security/logout\">". _t('ContentController.LOGOUT', 'Log out'). "</a>";
|
||||
} else {
|
||||
$logInMessage = _t('ContentController.NOTLOGGEDIN', 'Not logged in') ." - <a href=\"Security/login\">". _t('ContentController.LOGIN', 'Login') ."</a>";
|
||||
}
|
||||
$viewPageIn = _t('ContentController.VIEWPAGEIN', 'View Page in:');
|
||||
/**
|
||||
* HGS: cmsLink is now only set if there is a dataRecord. You can't view the page in the
|
||||
* CMS if there is no dataRecord
|
||||
*/
|
||||
|
||||
return <<<HTML
|
||||
<div id="SilverStripeNavigator">
|
||||
<div class="holder">
|
||||
@ -372,11 +363,7 @@ JS
|
||||
|
||||
<div id="switchView" class="bottomTabs">
|
||||
<div class="blank">$viewPageIn </div>
|
||||
$cmsLink
|
||||
$stageLink
|
||||
<div class="blank" style="width:1em;"> </div>
|
||||
$liveLink
|
||||
$archiveLink
|
||||
$items
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
80
core/control/SilverStripeNavigatorItem.php
Normal file
80
core/control/SilverStripeNavigatorItem.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Navigator items are links that appear in the $SilverStripeNavigator bar.
|
||||
* To add an item, extends this class.
|
||||
*/
|
||||
class SilverStripeNavigatorItem extends Object {
|
||||
function getHTML($controller) {}
|
||||
function getMessage($controller) {}
|
||||
}
|
||||
|
||||
class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem {
|
||||
static $priority = 10;
|
||||
|
||||
function getHTML($controller) {
|
||||
$cmsLink = 'admin/show/' . $controller->ID;
|
||||
$cmsLink = "<a href=\"$cmsLink\" target=\"cms\">". _t('ContentController.CMS', 'CMS') ."</a>";
|
||||
|
||||
return $cmsLink;
|
||||
}
|
||||
}
|
||||
|
||||
class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
|
||||
static $priority = 20;
|
||||
|
||||
function getHTML($controller) {
|
||||
if(Versioned::current_stage() == 'Stage') {
|
||||
return "<a class=\"current\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</a>";
|
||||
} else {
|
||||
$thisPage = $controller->Link();
|
||||
return "<a href=\"$thisPage?stage=Stage\" target=\"site\" style=\"left : -1px;\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</a>";
|
||||
}
|
||||
}
|
||||
|
||||
function getMessage($controller) {
|
||||
if(Versioned::current_stage() == 'Stage') {
|
||||
return "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.DRAFTSITE', 'Draft Site') ."</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
|
||||
static $priority = 30;
|
||||
|
||||
function getHTML($controller) {
|
||||
if(Versioned::current_stage() == 'Live') {
|
||||
return "<a class=\"current\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</a>";
|
||||
} else {
|
||||
$thisPage = $controller->Link();
|
||||
return "<a href=\"$thisPage?stage=Live\" target=\"site\" style=\"left : -3px;\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</a>";
|
||||
}
|
||||
}
|
||||
|
||||
function getMessage($controller) {
|
||||
if(Versioned::current_stage() == 'Live') {
|
||||
return "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.PUBLISHEDSITE', 'Published Site') ."</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
|
||||
static $priority = 40;
|
||||
|
||||
function getHTML($controller) {
|
||||
if(Versioned::current_archived_date()) {
|
||||
return "<a class=\"current\">". _t('ContentController.ARCHIVEDSITE', 'Archived Site') ."</a>";
|
||||
}
|
||||
}
|
||||
|
||||
function getMessage($controller) {
|
||||
if($date = Versioned::current_archived_date()) {
|
||||
$dateObj = Object::create('Datetime', $date, null);
|
||||
|
||||
return "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.ARCHIVEDSITEFROM', 'Archived site from') ."<br>" . $dateObj->Nice() . "</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user