FIX Don't offer to restore to root if can_be_root is false

This commit is contained in:
Mike Cochrane 2018-05-01 15:00:00 +12:00 committed by Guy Sartorelli
parent c130b55ecb
commit b46876b8a8
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A

View File

@ -2470,7 +2470,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Note: It would be nice to have a canRestore() permission at some point // Note: It would be nice to have a canRestore() permission at some point
if ($canEdit && !$isOnDraft && !$isPublished) { if ($canEdit && !$isOnDraft && !$isPublished) {
// Determine if we should force a restore to root (where once it was a subpage) // 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" // "restore"
$title = $restoreToRoot $title = $restoreToRoot
@ -2479,13 +2479,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$description = $restoreToRoot $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_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'); : _t('SilverStripe\\CMS\\Controllers\\CMSMain.RESTORE_DESC', 'Restore the archived version to draft');
$majorActions->push( if (!$this->isParentArchived() || $restoreToRoot) {
FormAction::create('restore', $title) $majorActions->push(
->setDescription($description) FormAction::create('restore', $title)
->setAttribute('data-to-root', $restoreToRoot) ->setDescription($description)
->addExtraClass('btn-warning font-icon-back-in-time') ->setAttribute('data-to-root', $restoreToRoot)
->setUseButtonTag(true) ->addExtraClass('btn-warning font-icon-back-in-time')
); ->setUseButtonTag(true)
);
}
} }
// If a page is on any stage it can be archived // If a page is on any stage it can be archived