diff --git a/_config/versionedgridfield.yml b/_config/versionedgridfield.yml index 23c08919..9e446ee3 100644 --- a/_config/versionedgridfield.yml +++ b/_config/versionedgridfield.yml @@ -7,14 +7,9 @@ SilverStripe\Forms\GridField\GridFieldDetailForm: # Add status row to gridfields by default SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor: extensions: - - SilverStripe\Versioned\VersionedGridFieldStateExtension - SilverStripe\Versioned\VersionedGridFieldArchiveExtension -SilverStripe\Forms\GridField\GridFieldConfig_Base: - extensions: - - SilverStripe\Versioned\VersionedGridFieldStateExtension SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor: extensions: - - SilverStripe\Versioned\VersionedGridFieldStateExtension - SilverStripe\Versioned\VersionedGridFieldArchiveExtension # Enable gridfield extensions for dataobjects by default SilverStripe\ORM\DataObject: diff --git a/src/Versioned.php b/src/Versioned.php index 87858e5a..f4e56f9e 100644 --- a/src/Versioned.php +++ b/src/Versioned.php @@ -2981,4 +2981,42 @@ public function Publisher() $member = DataObject::get_by_id(Member::class, $this->owner->PublisherID); return $member; } + + protected function updateStatusFlags(array &$flags): void + { + if ($this->isOnLiveOnly()) { + $flags['removedfromdraft'] = [ + 'text' => _t(__CLASS__ . '.FLAG_ONLIVEONLY_SHORT', 'On live only'), + 'title' => _t( + __CLASS__ . '.FLAG_ONLIVEONLYSHORT_HELP', + 'Item is published, but has been deleted from draft' + ), + ]; + return; + } + + if ($this->isArchived()) { + $flags['archived'] = [ + 'text' => _t(__CLASS__ . '.FLAG_ARCHIVED_SHORT', 'Archived'), + 'title' => _t(__CLASS__ . '.FLAG_ARCHIVED_HELP', 'Item is removed from draft and live'), + ]; + return; + } + + if ($this->isOnDraftOnly()) { + $flags['addedtodraft'] = [ + 'text' => _t(__CLASS__ . '.FLAG_ADDEDTODRAFT_SHORT', 'Draft'), + 'title' => _t(__CLASS__ . '.FLAG_ADDEDTODRAFT_HELP', 'Item has not been published yet') + ]; + return; + } + + if ($this->isModifiedOnDraft()) { + $flags['modified'] = [ + 'text' => _t(__CLASS__ . '.FLAG_MODIFIEDONDRAFT_SHORT', 'Modified'), + 'title' => _t(__CLASS__ . '.FLAG_MODIFIEDONDRAFT_HELP', 'Item has unpublished changes'), + ]; + return; + } + } } diff --git a/src/VersionedGridFieldItemRequest.php b/src/VersionedGridFieldItemRequest.php index fdcefabf..e05bd4e8 100644 --- a/src/VersionedGridFieldItemRequest.php +++ b/src/VersionedGridFieldItemRequest.php @@ -12,11 +12,8 @@ use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\Tab; use SilverStripe\Forms\TabSet; -use SilverStripe\Model\List\ArrayList; use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\FieldType\DBField; use SilverStripe\Core\Validation\ValidationResult; -use SilverStripe\Model\ArrayData; use SilverStripe\View\SSViewer; /** @@ -26,29 +23,6 @@ */ class VersionedGridFieldItemRequest extends GridFieldDetailForm_ItemRequest { - public function Breadcrumbs($unlinked = false) - { - $items = parent::Breadcrumbs($unlinked); - $status = $this->getRecordStatus(); - $badge = null; - if ($status) { - // Generate badge - $badge = DBField::create_field('HTMLFragment', sprintf( - '%s', - $status['class'], - $status['title'] - )); - } - $this->extend('updateBadge', $badge); - - if ($badge) { - $lastItem = $items->last(); - $lastItem->setField('Extra', $badge); - } - - return $items; - } - /** * @return FieldList */ @@ -244,38 +218,6 @@ protected function setFormMessage($form, $message) } } - /** - * Return list of class / title to add on the end of record status in breadcrumbs - * - * @return array|null - */ - protected function getRecordStatus() - { - /** @var DataObject|Versioned $record */ - $record = $this->record; - - // No status if un-versioned - if (!$this->record->hasExtension(Versioned::class)) { - return null; - } - - if ($record->isOnDraftOnly()) { - return [ - 'class' => 'addedtodraft', - 'title' => _t(__CLASS__ . '.DRAFT', 'Draft') - ]; - } - - if ($record->isModifiedOnDraft()) { - return [ - 'class' => 'modified', - 'title' => _t(__CLASS__ . '.MODIFIED', 'Modified') - ]; - } - - return null; - } - /** * Getting buttons that are for versioned objects * diff --git a/src/VersionedGridFieldState/VersionedGridFieldState.php b/src/VersionedGridFieldState/VersionedGridFieldState.php deleted file mode 100644 index 65b5dda6..00000000 --- a/src/VersionedGridFieldState/VersionedGridFieldState.php +++ /dev/null @@ -1,239 +0,0 @@ -setVersionedLabelFields($versionedLabelFields); - } - - /** - * Column to decorate with version state - * - * @return string - */ - public function getColumn() - { - return $this->column; - } - - /** - * @param string $column - * @return VersionedGridFieldState - */ - public function setColumn($column) - { - $this->column = $column; - return $this; - } - - /** - * Search list for default column - * - * @return array - */ - public function getVersionedLabelFields() - { - return $this->versionedLabelFields; - } - - /** - * @param array $versionedLabelFields - * @return VersionedGridFieldState - */ - public function setVersionedLabelFields($versionedLabelFields) - { - $this->versionedLabelFields = $versionedLabelFields; - return $this; - } - - /** - * Modify the list of columns displayed in the table. - * - * @see {@link GridFieldDataColumns->getDisplayFields()} - * @see {@link GridFieldDataColumns}. - * - * @param GridField $gridField - * @param array $columns List reference of all column names. - */ - public function augmentColumns($gridField, &$columns) - { - $model = $gridField->getModelClass(); - $isModelVersioned = $model::has_extension(Versioned::class); - - // Skip if not versioned, or column already set - if (!$isModelVersioned || $this->getColumn()) { - return; - } - - $matchedVersionedFields = array_intersect( - $columns ?? [], - $this->versionedLabelFields - ); - - if (count($matchedVersionedFields ?? []) > 0) { - // Get first matched column - $this->setColumn(reset($matchedVersionedFields)); - } elseif ($columns) { - // Use first column if none of preferred matches - $this->setColumn(reset($columns)); - } - } - - /** - * Names of all columns which are affected by this component. - * - * @param GridField $gridField - * @return array - */ - public function getColumnsHandled($gridField) - { - return $this->getColumn() ? [$this->getColumn()] : []; - } - - /** - * HTML for the column, content of the