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
|
## Requirements
|
||||||
|
|
||||||
SilverStripe 3.1
|
SilverStripe 4.0
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
---
|
---
|
||||||
Name: betternavigator
|
Name: betternavigator
|
||||||
After: 'framework/*','cms/*'
|
After: 'framework/*, cms/*'
|
||||||
---
|
---
|
||||||
LeftAndMain:
|
SilverStripe\Admin\LeftAndMain:
|
||||||
extra_requirements_javascript:
|
extra_requirements_javascript:
|
||||||
- 'betternavigator/javascript/BN.LeftAndMain.Preview.js'
|
- 'betternavigator/javascript/BN.LeftAndMain.Preview.js'
|
||||||
ContentController:
|
SilverStripe\CMS\Controllers\ContentController:
|
||||||
extensions:
|
extensions:
|
||||||
- BetterNavigatorExtension
|
- JonoM\BetterNavigator\Extension\BetterNavigatorExtension
|
||||||
|
@ -2,16 +2,26 @@
|
|||||||
"name": "jonom/silverstripe-betternavigator",
|
"name": "jonom/silverstripe-betternavigator",
|
||||||
"description": "Front-end utility menu for SilverStripe websites featuring administration and development tools",
|
"description": "Front-end utility menu for SilverStripe websites featuring administration and development tools",
|
||||||
"type": "silverstripe-module",
|
"type": "silverstripe-module",
|
||||||
"keywords": ["silverstripe", "navigator", "SilverStripeNavigator", "BetterNavigator"],
|
"keywords": [
|
||||||
|
"silverstripe",
|
||||||
|
"navigator",
|
||||||
|
"SilverStripeNavigator",
|
||||||
|
"BetterNavigator"
|
||||||
|
],
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"authors": [{
|
"authors": [
|
||||||
|
{
|
||||||
"name": "Jonathon Menz",
|
"name": "Jonathon Menz",
|
||||||
"homepage": "http://jonathonmenz.com"
|
"homepage": "http://jonathonmenz.com"
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"silverstripe/framework": "~3.1"
|
"silverstripe/framework": "^4.0"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"installer-name": "betternavigator"
|
"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
|
<?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 {
|
class BetterNavigatorExtension extends DataExtension {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,25 +22,26 @@ class BetterNavigatorExtension extends DataExtension {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function BetterNavigator() {
|
public function BetterNavigator() {
|
||||||
|
|
||||||
// Make sure this is a page
|
// 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
|
// Only show navigator to appropriate users
|
||||||
$isDev = Director::isDev();
|
$isDev = Director::isDev();
|
||||||
$canViewDraft = (Permission::check('VIEW_DRAFT_CONTENT') || Permission::check('CMS_ACCESS_CMSMain'));
|
$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)
|
// Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
||||||
$nav = array();
|
$nav = [];
|
||||||
$viewing = '';
|
$viewing = '';
|
||||||
$navigator = new SilverStripeNavigator($this->owner->dataRecord);
|
$navigator = SilverStripeNavigator::create($this->owner->dataRecord);
|
||||||
$items = $navigator->getItems();
|
$items = $navigator->getItems();
|
||||||
foreach($items as $item) {
|
foreach ($items as $item) {
|
||||||
$name = $item->getName();
|
$name = $item->getName();
|
||||||
$active = $item->isActive();
|
$active = $item->isActive();
|
||||||
$nav[$name] = array(
|
$nav[$name] = [
|
||||||
'Link' => $item->getLink(),
|
'Link' => $item->getLink(),
|
||||||
'Active' => $active
|
'Active' => $active
|
||||||
);
|
];
|
||||||
if ($active) {
|
if ($active) {
|
||||||
if ($name == 'LiveLink') $viewing = 'Live';
|
if ($name == 'LiveLink') $viewing = 'Live';
|
||||||
if ($name == 'StageLink') $viewing = 'Draft';
|
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
|
// 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?
|
// Is the logged in member nominated as a developer?
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
@ -45,22 +62,29 @@ class BetterNavigatorExtension extends DataExtension {
|
|||||||
|
|
||||||
// Add other data for template
|
// Add other data for template
|
||||||
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
||||||
$bNData = array_merge($nav, array(
|
$bNData = array_merge($nav, [
|
||||||
'Member' => $member,
|
'Member' => $member,
|
||||||
'Stage' => Versioned::current_stage(),
|
'Stage' => Versioned::get_stage(),
|
||||||
'Viewing' => $viewing, // What we're viewing doesn't necessarily align with the active 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),
|
'LoginLink' => Controller::join_links(Director::absoluteBaseURL(), Config::inst()->get('Security', 'login_url'), $backURL),
|
||||||
'LogoutLink' => Controller::join_links(Director::absoluteBaseURL() . 'Security/logout', $backURL),
|
'LogoutLink' => Controller::join_links(Director::absoluteBaseURL() . 'Security/logout', $backURL),
|
||||||
'EditLink' => $editLink,
|
'EditLink' => $editLink,
|
||||||
'Mode' => Director::get_environment_type(),
|
'Mode' => Director::get_environment_type(),
|
||||||
'IsDeveloper' => $isDeveloper
|
'IsDeveloper' => $isDeveloper
|
||||||
));
|
]);
|
||||||
|
|
||||||
// Merge with page data, send to template and render
|
// Merge with page data, send to template and render
|
||||||
$bNData = new ArrayData($bNData);
|
$bNData = new ArrayData($bNData);
|
||||||
$page = $this->owner->customise(array('BetterNavigator' => $bNData));
|
$page = $this->owner->customise(['BetterNavigator' => $bNData]);
|
||||||
return $page->renderWith('BetterNavigator');
|
return $page->renderWith('BetterNavigator\\BetterNavigator');
|
||||||
}
|
}
|
||||||
return false;
|
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>
|
</div>
|
||||||
|
|
||||||
<% include BetterNavigatorExtraContent %>
|
<% include BetterNavigator\BetterNavigatorExtraContent %>
|
||||||
|
|
||||||
<% if $BetterNavigator.Mode=='dev' || $BetterNavigator.IsDeveloper %>
|
<% if $BetterNavigator.Mode=='dev' || $BetterNavigator.IsDeveloper %>
|
||||||
|
|
||||||
@ -65,7 +65,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% include BetterNavigatorExtraDevTools %>
|
<% include BetterNavigator\BetterNavigatorExtraDevTools %>
|
||||||
|
|
||||||
<div class="bn-heading">Debugging</div>
|
<div class="bn-heading">Debugging</div>
|
||||||
|
|
||||||
@ -81,7 +81,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% include BetterNavigatorExtraDebugging %>
|
<% include BetterNavigator\BetterNavigatorExtraDebugging %>
|
||||||
|
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user