Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH UI updated for versioned objects and all its relations #429

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ en:
Published: 'Published {name} {link}'
Unpublished: 'Unpublished {name} "{title}"'
PUBLISHEDTOASTMESSAGE: 'Published {type} "{title}"'
ROLLEDBACKPERMISSION: 'You do not have permission to roll back this record.'
ROLLEDBACKPUB: 'Rolled back to published version.'
ROLLEDBACKVERSION: 'Rolled back to version #{version}.'
SilverStripe\Versioned\VersionedGridFieldState\VersionedGridFieldState:
ADDEDTODRAFTHELP: 'Item has not been published yet'
ADDEDTODRAFTSHORT: Draft
Expand Down
61 changes: 60 additions & 1 deletion src/VersionedGridFieldItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\PjaxResponseNegotiator;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
Expand All @@ -15,6 +16,7 @@
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
Expand Down Expand Up @@ -234,6 +236,51 @@ public function doUnpublish($data, $form)
return $this->redirectAfterSave(false);
}

public function doRollback($data, $form): HTTPResponse|DBHTMLText
{
$version = $this->getRequest()->param('VersionID');
$this->extend('onBeforeRollback', $data['Version']);

/** @var Versioned|RecursivePublishable|DataObject $record */
$record = $this->getRecord();

// Check permission
if (!$record->canEdit()) {
return $this->httpError(
403,
_t(
__CLASS__ . '.ROLLEDBACKPERMISSION',
"You do not have permission to roll back this record."
)
);
}

if ($version) {
$record->rollbackRecursive($version);
$message = _t(
__CLASS__ . '.ROLLEDBACKVERSION',
"Rolled back to version #{version}.",
['version' => $version]
);
} else {
$record->doRevertToLive();
$record->publishRecursive();
$message = _t(
__CLASS__ . '.ROLLEDBACKPUB',
"Rolled back to published version."
);
}

$this->setFormMessage($form, $message);

$controller = $this->getToplevelController();
$controller->getResponse()->addHeader('X-ControllerURL', $this->Link('edit'));
$controller->getResponse()->addHeader('X-Pjax', 'Content');
$controller->getResponse()->addHeader('X-Status', $message);

return $this->redirectAfterSave(false);
}

/**
* @param Form $form
* @param string $message
Expand Down Expand Up @@ -292,7 +339,7 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions)
// Get status of the object
$isOnDraft = $record->isOnDraft();
$isPublished = $record->isPublished();
$stagesDiffer = $record->stagesDiffer();
$stagesDiffer = $record->stagesDiffer || $record->stagesDifferRecursive();

// Check permissions
$canPublish = $record->canPublish();
Expand Down Expand Up @@ -362,6 +409,18 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions)
}
}

// "rollback"
if ($isOnDraft && $isPublished && $canEdit && $stagesDiffer) {
$moreOptions->push(
FormAction::create('doRollback', _t(__CLASS__.'.BUTTONCANCELDRAFT', 'Cancel draft changes'))
->setDescription(_t(
'SilverStripe\\CMS\\Model\\SiteTree.BUTTONCANCELDRAFTDESC',
'Delete your draft and revert to the currently published page'
))
->addExtraClass('btn-secondary')
);
}

// "unpublish" action
if ($isPublished && $isOnDraft && $canUnpublish) {
$actionUnpublish = FormAction::create(
Expand Down
2 changes: 1 addition & 1 deletion src/VersionedGridFieldState/VersionedGridFieldState.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected function getStatusFlags($record)
];
}

if ($record->isModifiedOnDraft()) {
if ($record->isModifiedOnDraft() || $record->stagesDifferRecursive()) {
return [
'modified' => [
'text' => _t(__CLASS__ . '.MODIFIEDONDRAFTSHORT', 'Modified'),
Expand Down