Merge pull request #2768 from creative-commoners/pulls/5/rescue-master-canberoot-check

Rescue Master Branch PR: FIX Don't offer to restore to root if can_be_root is false
This commit is contained in:
Steve Boyd 2022-08-29 18:07:56 +12:00 committed by GitHub
commit f9a19e7429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
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