Skip to content

Commit

Permalink
Add support for Silverstripe 5
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispenny committed Feb 12, 2023
1 parent aaa76de commit 77285e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ This module is intended to replicate and expand upon the functionality provided

## Requirements

Silverstripe 4.0 (3.1+ through previous releases)
Silverstripe 5.0 (4.0 and 3.1+ through previous releases)

## Installation

**Composer / Packagist ([best practice](http://doc.silverstripe.org/framework/en/trunk/installation/composer))**
Add "jonom/silverstripe-betternavigator" to your requirements.

```
composer require jonom/silverstripe-betternavigator
```

**Manually**
Download, place the folder in your project root, rename it to 'betternavigator' (if applicable) and run a dev/build?flush=1.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"silverstripe/framework": "^4.0"
"silverstripe/framework": "^5"
},
"extra": {
"installer-name": "betternavigator",
Expand Down
19 changes: 14 additions & 5 deletions src/Extension/BetterNavigatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JonoM\BetterNavigator\Extension;

use SilverStripe\CMS\Controllers\SilverStripeNavigator;
use SilverStripe\Admin\Navigator\SilverStripeNavigator;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
Expand All @@ -23,6 +23,11 @@ class BetterNavigatorExtension extends DataExtension
private static $better_navigator_edit_permission = 'CMS_ACCESS_CMSMain';
private static $better_navigator_edit_permission_mode = 'any';

/**
* Extensions are singleton, so any cached results need to use a unique key
*/
private $shouldDisplay = [];

/**
* @param $request
* @param $action
Expand Down Expand Up @@ -161,13 +166,16 @@ private function generateNavigator()
*/
private function shouldDisplay()
{
if ($this->owner->getField('_betterNavigatorShouldDisplay') !== null) {
return $this->owner->getField('_betterNavigatorShouldDisplay');
$key = $this->owner->getUniqueKey();

if (array_key_exists($key, $this->shouldDisplay)) {
return $this->shouldDisplay[$key];
}

// Make sure this is a page
if (!$this->owner->showBetterNavigator()) {
$this->owner->setField('_betterNavigatorShouldDisplay', false);
$this->shouldDisplay[$key] = false;

return false;
}

Expand All @@ -176,7 +184,8 @@ private function shouldDisplay()
$canViewDraft = (Permission::check('VIEW_DRAFT_CONTENT') || Permission::check('CMS_ACCESS_CMSMain'));

$result = ($isDev || $canViewDraft);
$this->owner->setField('_betterNavigatorShouldDisplay', $result);
$this->shouldDisplay[$key] = $result;

return $result;
}

Expand Down
4 changes: 2 additions & 2 deletions templates/BetterNavigator/BetterNavigator.ss
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
<span class="bn-icon-flush"></span>
<%t JonoM\BetterNavigator.FLUSH_CACHE_LABEL 'Flush caches' %>
</a>
<a href="{$AbsoluteBaseURL}dev/build/?flush=1"
<a href="/dev/build/?flush=1"
target="_blank"
title="<%t JonoM\BetterNavigator.BUILD_DATABASE_TITLE 'Build database and flush caches (excludes template caches pre SS-3.1.7)' %>"
>
<span class="bn-icon-db"></span>
<%t JonoM\BetterNavigator.BUILD_DATABASE_LABEL 'Build database' %>
</a>
<a href="{$AbsoluteBaseURL}dev/" target="_blank"><span class="bn-icon-tools"></span><%t JonoM\BetterNavigator.DEV_MENU_LABEL 'Dev menu' %></a>
<a href="/dev/" target="_blank"><span class="bn-icon-tools"></span><%t JonoM\BetterNavigator.DEV_MENU_LABEL 'Dev menu' %></a>

</div>

Expand Down

0 comments on commit 77285e8

Please sign in to comment.