From b46876b8a8959b15274bef9163530be3a6e2d678 Mon Sep 17 00:00:00 2001 From: Mike Cochrane Date: Tue, 1 May 2018 15:00:00 +1200 Subject: [PATCH] FIX Don't offer to restore to root if can_be_root is false --- code/Model/SiteTree.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 2c19f445..8fe1c0ef 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -2470,7 +2470,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi // Note: It would be nice to have a canRestore() permission at some point if ($canEdit && !$isOnDraft && !$isPublished) { // Determine if we should force a restore to root (where once it was a subpage) - $restoreToRoot = $this->isParentArchived(); + $restoreToRoot = $this->isParentArchived() && $this->config()->get('can_be_root'); // "restore" $title = $restoreToRoot @@ -2479,13 +2479,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi $description = $restoreToRoot ? _t('SilverStripe\\CMS\\Controllers\\CMSMain.RESTORE_TO_ROOT_DESC', 'Restore the archived version to draft as a top level page') : _t('SilverStripe\\CMS\\Controllers\\CMSMain.RESTORE_DESC', 'Restore the archived version to draft'); - $majorActions->push( - FormAction::create('restore', $title) - ->setDescription($description) - ->setAttribute('data-to-root', $restoreToRoot) - ->addExtraClass('btn-warning font-icon-back-in-time') - ->setUseButtonTag(true) - ); + if (!$this->isParentArchived() || $restoreToRoot) { + $majorActions->push( + FormAction::create('restore', $title) + ->setDescription($description) + ->setAttribute('data-to-root', $restoreToRoot) + ->addExtraClass('btn-warning font-icon-back-in-time') + ->setUseButtonTag(true) + ); + } } // If a page is on any stage it can be archived