diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 8dc694bb..c6a0d877 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -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( + '%s', + '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. diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index f8e2b9d1..c5e81730 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -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'), diff --git a/lang/en.yml b/lang/en.yml index 610afc91..9dbbc7b2 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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'