Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Silverstripe 5 #61

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 15 additions & 6 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 @@ -152,7 +157,7 @@ private function generateNavigator()
// Merge with page data, send to template and render
$navigator = new ArrayData($bNData);

return $this->owner->customise($navigator)->renderWith('BetterNavigator\\BetterNavigator');
return $this->owner->customise($navigator)->renderWith('JonoM\\BetterNavigator\\BetterNavigator');
}

/**
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

</div>

<% include BetterNavigator\BetterNavigatorExtraContent %>
<% include JonoM\BetterNavigator\BetterNavigatorExtraContent %>

<% if $Mode == 'dev' || $IsDeveloper %>

Expand All @@ -62,18 +62,18 @@
<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>

<% include BetterNavigator\BetterNavigatorExtraDevTools %>
<% include JonoM\BetterNavigator\BetterNavigatorExtraDevTools %>

<% end_if %>

Expand Down Expand Up @@ -128,7 +128,7 @@

</div>

<% include BetterNavigator\BetterNavigatorExtraDebugging %>
<% include JonoM\BetterNavigator\BetterNavigatorExtraDebugging %>

<% end_if %>

Expand Down