From c8ccd6a8c4be0558c0dd7099e54db890ed28916a Mon Sep 17 00:00:00 2001 From: Lee Bradley Date: Wed, 30 Oct 2019 09:02:18 +0000 Subject: [PATCH] Amends made requested during Pull Request Requested by @andrewandante & @ScopeyNZ --- .../SilverStripeNavigatorItem_LiveLink.php | 13 ++++++------- .../SilverStripeNavigatorItem_StageLink.php | 13 ++++++------- code/Model/SiteTree.php | 8 ++++++++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/code/Controllers/SilverStripeNavigatorItem_LiveLink.php b/code/Controllers/SilverStripeNavigatorItem_LiveLink.php index ccbc3be4..0dd68258 100644 --- a/code/Controllers/SilverStripeNavigatorItem_LiveLink.php +++ b/code/Controllers/SilverStripeNavigatorItem_LiveLink.php @@ -3,6 +3,7 @@ namespace SilverStripe\CMS\Controllers; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\Control\Controller; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; use SilverStripe\ORM\DataObject; use SilverStripe\Versioned\Versioned; @@ -56,20 +57,18 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem $record = $this->record; return ( $record->hasExtension(Versioned::class) + && $this->showLiveLink() && $record->hasStages() && $this->getLivePage() - && $this->showLiveLink() ); } + /** + * @return bool + */ public function showLiveLink() { - try { - return $this->record->config()->get('show_live_link'); - } catch (\BadMethodCallException $e) { - // Not using `config()` or similar - return false; - } + return (bool)Config::inst()->get(get_class($this->record), 'show_live_link'); } public function isActive() diff --git a/code/Controllers/SilverStripeNavigatorItem_StageLink.php b/code/Controllers/SilverStripeNavigatorItem_StageLink.php index 653f013e..2c623c01 100644 --- a/code/Controllers/SilverStripeNavigatorItem_StageLink.php +++ b/code/Controllers/SilverStripeNavigatorItem_StageLink.php @@ -3,6 +3,7 @@ namespace SilverStripe\CMS\Controllers; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\Control\Controller; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Convert; use SilverStripe\ORM\DataObject; @@ -62,20 +63,18 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem $record = $this->record; return ( $record->hasExtension(Versioned::class) + && $this->showStageLink() && $record->hasStages() && $this->getDraftPage() - && $this->showStageLink() ); } + /** + * @return bool + */ public function showStageLink() { - try { - return $this->record->config()->get('show_stage_link'); - } catch (\BadMethodCallException $e) { - // Not using `config()` or similar - return false; - } + return (bool)Config::inst()->get(get_class($this->record), 'show_stage_link'); } public function isActive() diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index c9ba168e..c3c8d911 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -137,8 +137,16 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi */ protected static $_allowedChildren = array(); + /** + * Determines if the Draft Preview panel will appear when in the CMS admin + * @var bool + */ private static $show_stage_link = true; + /** + * Determines if the Live Preview panel will appear when in the CMS admin + * @var bool + */ private static $show_live_link = true; /**