mirror of
https://github.com/jonom/silverstripe-betternavigator.git
synced 2024-10-22 14:05:51 +02:00
parent
63f16e4054
commit
79a585eda4
@ -17,7 +17,7 @@ This module is intended to replicate and expand upon the functionality provided
|
||||
|
||||
## Requirements
|
||||
|
||||
SilverStripe 3.1
|
||||
SilverStripe 4.0
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
Name: betternavigator
|
||||
After: 'framework/*','cms/*'
|
||||
After: 'framework/*, cms/*'
|
||||
---
|
||||
LeftAndMain:
|
||||
SilverStripe\Admin\LeftAndMain:
|
||||
extra_requirements_javascript:
|
||||
- 'betternavigator/javascript/BN.LeftAndMain.Preview.js'
|
||||
ContentController:
|
||||
SilverStripe\CMS\Controllers\ContentController:
|
||||
extensions:
|
||||
- BetterNavigatorExtension
|
||||
- JonoM\BetterNavigator\Extension\BetterNavigatorExtension
|
||||
|
@ -1,17 +1,27 @@
|
||||
{
|
||||
"name": "jonom/silverstripe-betternavigator",
|
||||
"description": "Front-end utility menu for SilverStripe websites featuring administration and development tools",
|
||||
"type": "silverstripe-module",
|
||||
"keywords": ["silverstripe", "navigator", "SilverStripeNavigator", "BetterNavigator"],
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [{
|
||||
"name": "Jonathon Menz",
|
||||
"homepage": "http://jonathonmenz.com"
|
||||
}],
|
||||
"require": {
|
||||
"silverstripe/framework": "~3.1"
|
||||
},
|
||||
"extra": {
|
||||
"installer-name": "betternavigator"
|
||||
}
|
||||
"name": "jonom/silverstripe-betternavigator",
|
||||
"description": "Front-end utility menu for SilverStripe websites featuring administration and development tools",
|
||||
"type": "silverstripe-module",
|
||||
"keywords": [
|
||||
"silverstripe",
|
||||
"navigator",
|
||||
"SilverStripeNavigator",
|
||||
"BetterNavigator"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jonathon Menz",
|
||||
"homepage": "http://jonathonmenz.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "^4.0"
|
||||
},
|
||||
"extra": {
|
||||
"installer-name": "betternavigator"
|
||||
},
|
||||
"autoload": {
|
||||
"Jonom\\BetterNavigator\\": "src/"
|
||||
}
|
||||
}
|
||||
|
50
code/BetterNavigatorExtension.php → src/Extension/BetterNavigatorExtension.php
Executable file → Normal file
50
code/BetterNavigatorExtension.php → src/Extension/BetterNavigatorExtension.php
Executable file → Normal file
@ -1,5 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace JonoM\BetterNavigator\Extension;
|
||||
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
|
||||
class BetterNavigatorExtension extends DataExtension {
|
||||
|
||||
/**
|
||||
@ -9,25 +22,26 @@ class BetterNavigatorExtension extends DataExtension {
|
||||
* @return string
|
||||
*/
|
||||
public function BetterNavigator() {
|
||||
|
||||
// Make sure this is a page
|
||||
if (!($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree && $this->owner->dataRecord->ID > 0)) return false;
|
||||
if (!$this->isAPage()) return false;
|
||||
|
||||
// Only show navigator to appropriate users
|
||||
$isDev = Director::isDev();
|
||||
$canViewDraft = (Permission::check('VIEW_DRAFT_CONTENT') || Permission::check('CMS_ACCESS_CMSMain'));
|
||||
if($isDev || $canViewDraft) {
|
||||
if ($isDev || $canViewDraft) {
|
||||
// Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
||||
$nav = array();
|
||||
$nav = [];
|
||||
$viewing = '';
|
||||
$navigator = new SilverStripeNavigator($this->owner->dataRecord);
|
||||
$navigator = SilverStripeNavigator::create($this->owner->dataRecord);
|
||||
$items = $navigator->getItems();
|
||||
foreach($items as $item) {
|
||||
foreach ($items as $item) {
|
||||
$name = $item->getName();
|
||||
$active = $item->isActive();
|
||||
$nav[$name] = array(
|
||||
$nav[$name] = [
|
||||
'Link' => $item->getLink(),
|
||||
'Active' => $active
|
||||
);
|
||||
];
|
||||
if ($active) {
|
||||
if ($name == 'LiveLink') $viewing = 'Live';
|
||||
if ($name == 'StageLink') $viewing = 'Draft';
|
||||
@ -35,7 +49,10 @@ class BetterNavigatorExtension extends DataExtension {
|
||||
}
|
||||
}
|
||||
// Only show edit link if user has permission to edit this page
|
||||
$editLink = (($this->owner->dataRecord->canEdit() && Permission::check('CMS_ACCESS_CMSMain')) || $isDev) ? Controller::join_links(Director::absoluteBaseURL(), $nav['CMSLink']['Link']) : false;
|
||||
$editLink = false;
|
||||
if ($this->owner->dataRecord->canEdit() && Permission::check('CMS_ACCESS_CMSMain') || $isDev) {
|
||||
$editLink = $nav['CMSLink']['Link'];
|
||||
}
|
||||
|
||||
// Is the logged in member nominated as a developer?
|
||||
$member = Member::currentUser();
|
||||
@ -45,22 +62,29 @@ class BetterNavigatorExtension extends DataExtension {
|
||||
|
||||
// Add other data for template
|
||||
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
||||
$bNData = array_merge($nav, array(
|
||||
$bNData = array_merge($nav, [
|
||||
'Member' => $member,
|
||||
'Stage' => Versioned::current_stage(),
|
||||
'Stage' => Versioned::get_stage(),
|
||||
'Viewing' => $viewing, // What we're viewing doesn't necessarily align with the active Stage
|
||||
'LoginLink' => Controller::join_links(Director::absoluteBaseURL(), Config::inst()->get('Security', 'login_url'), $backURL),
|
||||
'LogoutLink' => Controller::join_links(Director::absoluteBaseURL() . 'Security/logout', $backURL),
|
||||
'EditLink' => $editLink,
|
||||
'Mode' => Director::get_environment_type(),
|
||||
'IsDeveloper' => $isDeveloper
|
||||
));
|
||||
]);
|
||||
|
||||
// Merge with page data, send to template and render
|
||||
$bNData = new ArrayData($bNData);
|
||||
$page = $this->owner->customise(array('BetterNavigator' => $bNData));
|
||||
return $page->renderWith('BetterNavigator');
|
||||
$page = $this->owner->customise(['BetterNavigator' => $bNData]);
|
||||
return $page->renderWith('BetterNavigator\\BetterNavigator');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function isAPage() {
|
||||
return $this->owner
|
||||
&& $this->owner->dataRecord
|
||||
&& $this->owner->dataRecord instanceof SiteTree
|
||||
&& $this->owner->dataRecord->ID > 0;
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<% include BetterNavigatorExtraContent %>
|
||||
<% include BetterNavigator\BetterNavigatorExtraContent %>
|
||||
|
||||
<% if $BetterNavigator.Mode=='dev' || $BetterNavigator.IsDeveloper %>
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<% include BetterNavigatorExtraDevTools %>
|
||||
<% include BetterNavigator\BetterNavigatorExtraDevTools %>
|
||||
|
||||
<div class="bn-heading">Debugging</div>
|
||||
|
||||
@ -81,7 +81,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<% include BetterNavigatorExtraDebugging %>
|
||||
<% include BetterNavigator\BetterNavigatorExtraDebugging %>
|
||||
|
||||
<% end_if %>
|
||||
|
Loading…
Reference in New Issue
Block a user