mirror of
https://github.com/jonom/silverstripe-betternavigator.git
synced 2024-10-22 14:05:51 +02:00
Add config option to use absolute links inside the widget
This commit is contained in:
parent
e0a82db467
commit
a807650a66
12
README.md
12
README.md
@ -32,6 +32,7 @@ Download, place the folder in your project root, rename it to 'betternavigator'
|
|||||||
Just place **$BetterNavigator** somewhere in your template(s). If your website uses caching, make sure BetterNavigator's output is excluded.
|
Just place **$BetterNavigator** somewhere in your template(s). If your website uses caching, make sure BetterNavigator's output is excluded.
|
||||||
|
|
||||||
**Access developer tools on a live website**
|
**Access developer tools on a live website**
|
||||||
|
|
||||||
You can mark certain CMS users as developers in your site's config, so they can access developer tools when logged in. Example YAML:
|
You can mark certain CMS users as developers in your site's config, so they can access developer tools when logged in. Example YAML:
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -41,6 +42,17 @@ You can mark certain CMS users as developers in your site's config, so they can
|
|||||||
- 'otherdev@yoursite.com'
|
- 'otherdev@yoursite.com'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Use absolute links**
|
||||||
|
|
||||||
|
Some sites may opt to not use base tag in the page head (e.g. it could be problematic with hash links within a page).
|
||||||
|
In that case you can use this YAML settings to force output of absolute links always starting with a slash.
|
||||||
|
|
||||||
|
```
|
||||||
|
BetterNavigator:
|
||||||
|
developers:
|
||||||
|
useAbsoluteLinks: true
|
||||||
|
```
|
||||||
|
|
||||||
##Customisation
|
##Customisation
|
||||||
|
|
||||||
BetterNavigator's output is controlled by templates so it can be [easily overridden](http://doc.silverstripe.org/framework/en/topics/theme-development#overriding).
|
BetterNavigator's output is controlled by templates so it can be [easily overridden](http://doc.silverstripe.org/framework/en/topics/theme-development#overriding).
|
||||||
|
@ -16,6 +16,18 @@ class BetterNavigator extends DataExtension {
|
|||||||
*/
|
*/
|
||||||
private static $developers;
|
private static $developers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force use of absolute links starting with a slash for sites not using base tag
|
||||||
|
* Example YAML:
|
||||||
|
*
|
||||||
|
* BetterNavigator:
|
||||||
|
* useAbsoluteLinks: true
|
||||||
|
*
|
||||||
|
* @config
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private static $useAbsoluteLinks = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a front-end utility menu with administrative functions and developer tools
|
* Provides a front-end utility menu with administrative functions and developer tools
|
||||||
* Relies on SilverStripeNavigator
|
* Relies on SilverStripeNavigator
|
||||||
@ -30,6 +42,10 @@ class BetterNavigator extends DataExtension {
|
|||||||
$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) {
|
||||||
|
// use absolute links
|
||||||
|
$useAbsLinks = Config::inst()->get('BetterNavigator', 'useAbsoluteLinks');
|
||||||
|
$linkPrefix = ($useAbsLinks ? '/' : '');
|
||||||
|
|
||||||
// Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
// Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
||||||
$nav = array();
|
$nav = array();
|
||||||
$viewing = '';
|
$viewing = '';
|
||||||
@ -39,8 +55,8 @@ class BetterNavigator extends DataExtension {
|
|||||||
$name = $item->getName();
|
$name = $item->getName();
|
||||||
$active = $item->isActive();
|
$active = $item->isActive();
|
||||||
$nav[$name] = array(
|
$nav[$name] = array(
|
||||||
'Link' => $item->getLink(),
|
'Link' => (($name == 'CMSLink') ? $linkPrefix : '') . $item->getLink(),
|
||||||
'Active' => $active
|
'Active' => $active,
|
||||||
);
|
);
|
||||||
if ($active) {
|
if ($active) {
|
||||||
if ($name == 'LiveLink') $viewing = 'Live';
|
if ($name == 'LiveLink') $viewing = 'Live';
|
||||||
@ -54,8 +70,7 @@ class BetterNavigator extends DataExtension {
|
|||||||
// Is the logged in member nominated as a developer?
|
// Is the logged in member nominated as a developer?
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
$devs = Config::inst()->get('BetterNavigator', 'developers');
|
$devs = Config::inst()->get('BetterNavigator', 'developers');
|
||||||
$identifierField = Member::config()->unique_identifier_field;
|
$isDeveloper = $member && is_array($devs) ? in_array($member->Email, $devs) : false;
|
||||||
$isDeveloper = $member && is_array($devs) ? in_array($member->{$identifierField}, $devs) : false;
|
|
||||||
|
|
||||||
// Add other data for template
|
// Add other data for template
|
||||||
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
||||||
@ -63,11 +78,12 @@ class BetterNavigator extends DataExtension {
|
|||||||
'Member' => $member,
|
'Member' => $member,
|
||||||
'Stage' => Versioned::current_stage(),
|
'Stage' => Versioned::current_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' => Config::inst()->get('Security', 'login_url') . $backURL,
|
'LoginLink' => $linkPrefix . Config::inst()->get('Security', 'login_url') . $backURL,
|
||||||
'LogoutLink' => 'Security/logout' . $backURL,
|
'LogoutLink' => $linkPrefix . 'Security/logout' . $backURL,
|
||||||
'EditLink' => $editLink,
|
'EditLink' => $editLink,
|
||||||
'Mode' => Director::get_environment_type(),
|
'Mode' => Director::get_environment_type(),
|
||||||
'IsDeveloper' => $isDeveloper
|
'IsDeveloper' => $isDeveloper,
|
||||||
|
'LinkPrefix' => $linkPrefix,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Merge with page data, send to template and render
|
// Merge with page data, send to template and render
|
||||||
|
@ -60,8 +60,10 @@
|
|||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
|
||||||
<a href="$Link?flush=1" title="Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)"><span class="bn-icon-flush"></span>Flush caches</a>
|
<a href="$Link?flush=1" title="Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)"><span class="bn-icon-flush"></span>Flush caches</a>
|
||||||
<a href="dev/build/?flush=1" target="_blank" title="Build database and flush caches (excludes template caches pre SS-3.1.7)"><span class="bn-icon-db"></span>Build database</a>
|
<% with $BetterNavigator %>
|
||||||
<a href="dev" target="_blank"><span class="bn-icon-tools"></span>Dev menu</a>
|
<a href="{$LinkPrefix}dev/build/?flush=1" target="_blank" title="Build database and flush caches (excludes template caches pre SS-3.1.7)"><span class="bn-icon-db"></span>Build database</a>
|
||||||
|
<a href="{$LinkPrefix}dev" target="_blank"><span class="bn-icon-tools"></span>Dev menu</a>
|
||||||
|
<% end_with %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user