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 Oct 22, 2024
1 parent a7e5891 commit 71564cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 75 deletions.
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;
}
}
}
76 changes: 1 addition & 75 deletions src/VersionedGridFieldState/VersionedGridFieldState.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getColumnsHandled($gridField)
public function getColumnContent($gridField, $record, $columnName)
{
$flagContent = '';
$flags = $this->getStatusFlags($record);
$flags = $record->getStatusFlags();
foreach ($flags as $class => $data) {
$flagAttributes = [
'class' => "ss-gridfield-badge badge status-{$class}",
Expand Down Expand Up @@ -162,78 +162,4 @@ public function getColumnMetadata($gridField, $columnName)
{
return [];
}


/**
* A flag provides the user with additional data about the current item
* status, for example a "removed from draft" status. Each item can have
* more than one status flag. Returns a map of a unique key to a
* (localized) title for the flag. The unique key can be reused as a CSS
* class.
*
* Example (simple):
*
* ```php
* "deletedonlive" => "Deleted"
* ```
*
* Example (with optional title attribute):
*
* ```php
* "deletedonlive" => array(
* 'text' => "Deleted",
* 'title' => 'This page has been deleted'
* )
* ```
*
* @param Versioned|DataObject $record - the record to check status for
* @return array
*/
protected function getStatusFlags($record)
{
if (!$record->hasExtension(Versioned::class)) {
return [];
}

if ($record->isOnLiveOnly()) {
return [
'removedfromdraft' => [
'text' => _t(__CLASS__ . '.ONLIVEONLYSHORT', 'On live only'),
'title' => _t(
__CLASS__ . '.ONLIVEONLYSHORTHELP',
'Item is published, but has been deleted from draft'
),
]
];
}

if ($record->isArchived()) {
return [
'archived' => [
'text' => _t(__CLASS__ . '.ARCHIVEDPAGESHORT', 'Archived'),
'title' => _t(__CLASS__ . '.ARCHIVEDPAGEHELP', 'Item is removed from draft and live'),
]
];
}

if ($record->isOnDraftOnly()) {
return [
'addedtodraft' => [
'text' => _t(__CLASS__ . '.ADDEDTODRAFTSHORT', 'Draft'),
'title' => _t(__CLASS__ . '.ADDEDTODRAFTHELP', "Item has not been published yet")
]
];
}

if ($record->isModifiedOnDraft()) {
return [
'modified' => [
'text' => _t(__CLASS__ . '.MODIFIEDONDRAFTSHORT', 'Modified'),
'title' => _t(__CLASS__ . '.MODIFIEDONDRAFTHELP', 'Item has unpublished changes'),
]
];
}

return [];
}
}

0 comments on commit 71564cc

Please sign in to comment.