From 6bd08b9f27869b46896bc29d596beeb90efabc3c Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Mon, 13 Feb 2023 09:00:57 +1300 Subject: [PATCH 1/2] Add support for Silverstripe 5 --- README.md | 6 +++++- composer.json | 2 +- src/Extension/BetterNavigatorExtension.php | 19 ++++++++++++++----- templates/BetterNavigator/BetterNavigator.ss | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 25c8049..3c641b6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/composer.json b/composer.json index a5f125b..027fd78 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "silverstripe/framework": "^4.0" + "silverstripe/framework": "^5" }, "extra": { "installer-name": "betternavigator", diff --git a/src/Extension/BetterNavigatorExtension.php b/src/Extension/BetterNavigatorExtension.php index 72acdc1..5d8d83e 100644 --- a/src/Extension/BetterNavigatorExtension.php +++ b/src/Extension/BetterNavigatorExtension.php @@ -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; @@ -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 @@ -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; } @@ -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; } diff --git a/templates/BetterNavigator/BetterNavigator.ss b/templates/BetterNavigator/BetterNavigator.ss index 443eea6..2d95dca 100644 --- a/templates/BetterNavigator/BetterNavigator.ss +++ b/templates/BetterNavigator/BetterNavigator.ss @@ -62,14 +62,14 @@ <%t JonoM\BetterNavigator.FLUSH_CACHE_LABEL 'Flush caches' %> - <%t JonoM\BetterNavigator.BUILD_DATABASE_LABEL 'Build database' %> - <%t JonoM\BetterNavigator.DEV_MENU_LABEL 'Dev menu' %> + <%t JonoM\BetterNavigator.DEV_MENU_LABEL 'Dev menu' %> From bb151d1b2acba8a2881c6432b7811ef1ba56017a Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Tue, 14 Feb 2023 08:21:27 +1300 Subject: [PATCH 2/2] Move templates into JonoM namespaces --- src/Extension/BetterNavigatorExtension.php | 2 +- templates/{ => JonoM}/BetterNavigator/BetterNavigator.ss | 6 +++--- .../BetterNavigator/Includes/BetterNavigatorExtraContent.ss | 0 .../Includes/BetterNavigatorExtraDebugging.ss | 0 .../Includes/BetterNavigatorExtraDevTools.ss | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename templates/{ => JonoM}/BetterNavigator/BetterNavigator.ss (96%) rename templates/{ => JonoM}/BetterNavigator/Includes/BetterNavigatorExtraContent.ss (100%) rename templates/{ => JonoM}/BetterNavigator/Includes/BetterNavigatorExtraDebugging.ss (100%) rename templates/{ => JonoM}/BetterNavigator/Includes/BetterNavigatorExtraDevTools.ss (100%) diff --git a/src/Extension/BetterNavigatorExtension.php b/src/Extension/BetterNavigatorExtension.php index 5d8d83e..9658e89 100644 --- a/src/Extension/BetterNavigatorExtension.php +++ b/src/Extension/BetterNavigatorExtension.php @@ -157,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'); } /** diff --git a/templates/BetterNavigator/BetterNavigator.ss b/templates/JonoM/BetterNavigator/BetterNavigator.ss similarity index 96% rename from templates/BetterNavigator/BetterNavigator.ss rename to templates/JonoM/BetterNavigator/BetterNavigator.ss index 2d95dca..c7ce87c 100644 --- a/templates/BetterNavigator/BetterNavigator.ss +++ b/templates/JonoM/BetterNavigator/BetterNavigator.ss @@ -39,7 +39,7 @@ - <% include BetterNavigator\BetterNavigatorExtraContent %> + <% include JonoM\BetterNavigator\BetterNavigatorExtraContent %> <% if $Mode == 'dev' || $IsDeveloper %> @@ -73,7 +73,7 @@ - <% include BetterNavigator\BetterNavigatorExtraDevTools %> + <% include JonoM\BetterNavigator\BetterNavigatorExtraDevTools %> <% end_if %> @@ -128,7 +128,7 @@ - <% include BetterNavigator\BetterNavigatorExtraDebugging %> + <% include JonoM\BetterNavigator\BetterNavigatorExtraDebugging %> <% end_if %> diff --git a/templates/BetterNavigator/Includes/BetterNavigatorExtraContent.ss b/templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraContent.ss similarity index 100% rename from templates/BetterNavigator/Includes/BetterNavigatorExtraContent.ss rename to templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraContent.ss diff --git a/templates/BetterNavigator/Includes/BetterNavigatorExtraDebugging.ss b/templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraDebugging.ss similarity index 100% rename from templates/BetterNavigator/Includes/BetterNavigatorExtraDebugging.ss rename to templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraDebugging.ss diff --git a/templates/BetterNavigator/Includes/BetterNavigatorExtraDevTools.ss b/templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraDevTools.ss similarity index 100% rename from templates/BetterNavigator/Includes/BetterNavigatorExtraDevTools.ss rename to templates/JonoM/BetterNavigator/Includes/BetterNavigatorExtraDevTools.ss