ENH Updated UI for versioned objects and all its versioned relations

This commit is contained in:
Sabina Talipova 2023-12-21 13:48:35 +13:00
parent d5faa0158a
commit 4686193ca4
3 changed files with 65 additions and 2 deletions

View File

@ -54,6 +54,7 @@ use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\HiddenClass;
use SilverStripe\ORM\Hierarchy\Hierarchy;
@ -1089,11 +1090,65 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
]));
}
$badge = null;
$status = $this->getStatusFlag($record);
if (count($status) > 0) {
$flags = '';
foreach ($status as $flag => $flagData) {
$flags .= sprintf(
'<span class="badge version-status version-status--%s" %s>%s</span>',
'status-' . Convert::raw2xml($flag),
(isset($flagData['title'])) ? sprintf(' title="%s"', Convert::raw2xml($flagData['title'])) : '',
Convert::raw2xml($flagData['text'])
);
}
$badge = DBField::create_field('HTMLFragment', $flags);
}
$this->extend('updateBadge', $badge);
if ($badge) {
/** @var ArrayData $lastItem */
$lastItem = $items->last();
$lastItem->setField('Extra', $badge);
}
$this->extend('updateBreadcrumbs', $items);
return $items;
}
private function getStatusFlag($record)
{
$flags = [];
if ($record->isOnLiveOnly()) {
$flags['removedfromdraft'] = [
'text' => _t(__CLASS__.'.ONLIVEONLYSHORT', 'On live only'),
'title' => _t(__CLASS__.'.ONLIVEONLYSHORTHELP', 'Page is published, but has been deleted from draft'),
];
} elseif ($record->isArchived()) {
$flags['archived'] = [
'text' => _t(__CLASS__.'.ARCHIVEDPAGESHORT', 'Archived'),
'title' => _t(__CLASS__.'.ARCHIVEDPAGEHELP', 'Page is removed from draft and live'),
];
} elseif ($record->isOnDraftOnly()) {
$flags['addedtodraft'] = [
'text' => _t(__CLASS__.'.ADDEDTODRAFTSHORT', 'Draft'),
'title' => _t(__CLASS__.'.ADDEDTODRAFTHELP', 'Page has not been published yet')
];
} elseif ($record->isModifiedOnDraft() || $record->stagesDifferRecursive()) {
$flags['modified'] = [
'text' => _t(__CLASS__.'.MODIFIEDONDRAFTSHORT', 'Modified'),
'title' => _t(__CLASS__.'.MODIFIEDONDRAFTHELP', 'Page has unpublished changes'),
];
}
$this->extend('updateStatusFlags', $flags);
return $flags;
}
/**
* Create serialized JSON string with site tree hints data to be injected into
* 'data-hints' attribute of root node of jsTree.

View File

@ -2473,7 +2473,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Get status of page
$isOnDraft = $this->isOnDraft();
$isPublished = $this->isPublished();
$stagesDiffer = $this->stagesDiffer();
$stagesDiffer = $this->stagesDifferRecursive();
// Check permissions
$canPublish = $this->canPublish();
@ -2960,7 +2960,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
'text' => _t(__CLASS__.'.ADDEDTODRAFTSHORT', 'Draft'),
'title' => _t(__CLASS__.'.ADDEDTODRAFTHELP', "Page has not been published yet")
];
} elseif ($this->isModifiedOnDraft()) {
} elseif ($this->isModifiedOnDraft() || $this->stagesDifferRecursive()) {
$flags['modified'] = [
'text' => _t(__CLASS__.'.MODIFIEDONDRAFTSHORT', 'Modified'),
'title' => _t(__CLASS__.'.MODIFIEDONDRAFTHELP', 'Page has unpublished changes'),

View File

@ -14,8 +14,12 @@ en:
SilverStripe\CMS\Controllers\CMSMain:
ACCESS: "Access to '{title}' section"
ACCESS_HELP: 'Allow viewing of the section containing page tree and content. View and edit permissions can be handled through page specific dropdowns, as well as the separate "Content permissions".'
ADDEDTODRAFTSHORT: 'Draft'
ADDEDTODRAFTHELP: 'Page has not been published yet'
ARCHIVE: Archive
ARCHIVEDPAGE: "Archived page '{title}'"
ARCHIVEDPAGEHELP: 'Page is removed from draft and live'
ARCHIVEDPAGESHORT: 'Archived'
AddNew: 'Add new page'
AddNewButton: 'Add new'
AddPageRestriction: 'Note: Some page types are not allowed for this selection'
@ -31,7 +35,11 @@ en:
DUPLICATED: "Duplicated '{title}' successfully"
DUPLICATEDWITHCHILDREN: "Duplicated '{title}' and children successfully"
EMAIL: Email
MODIFIEDONDRAFTSHORT: 'Modified'
MODIFIEDONDRAFTHELP: 'Page has unpublished changes'
NEWPAGE: 'New {pagetype}'
ONLIVEONLYSHORT: 'On live only'
ONLIVEONLYSHORTHELP: 'Page is published, but has been deleted from draft'
PAGENOTEXISTS: "This page doesn't exist"
PAGES: 'Page status'
PAGESALLOPT: 'All pages'