Skip to content

Commit

Permalink
API Update API to reflect changes in silverstripe/framework
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 20, 2024
1 parent a7e5891 commit e6bb1fe
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 325 deletions.
5 changes: 0 additions & 5 deletions _config/versionedgridfield.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
58 changes: 0 additions & 58 deletions src/VersionedGridFieldItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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(
'<span class="badge version-status version-status--%s">%s</span>',
$status['class'],
$status['title']
));
}
$this->extend('updateBadge', $badge);

if ($badge) {
$lastItem = $items->last();
$lastItem->setField('Extra', $badge);
}

return $items;
}

/**
* @return FieldList
*/
Expand Down Expand Up @@ -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
*
Expand Down
239 changes: 0 additions & 239 deletions src/VersionedGridFieldState/VersionedGridFieldState.php

This file was deleted.

Loading

0 comments on commit e6bb1fe

Please sign in to comment.