Skip to content

Commit

Permalink
API Deprecate Versioned::canArchive()
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 13, 2024
1 parent 1c13b43 commit 09e2d35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/GridFieldArchiveAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\Versioned;

use SilverStripe\Control\Controller;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridField_ActionMenuItem;
use SilverStripe\Forms\GridField\GridField_ActionProvider;
Expand Down Expand Up @@ -176,7 +177,7 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
return;
}

if (!$item->canArchive()) {
if (!Deprecation::withNoReplacement(fn() => $item->canArchive())) {
throw new ValidationException(
_t(__CLASS__ . '.ArchivePermissionsFailure', "No archive permissions")
);
Expand All @@ -196,7 +197,7 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
public function getArchiveAction($gridField, $record)
{
/* @var DataObject|Versioned $record */
if (!$record->hasMethod('canArchive') || !$record->canArchive()) {
if (!$record->hasMethod('canArchive') || !Deprecation::withNoReplacement(fn() => $record->canArchive())) {
return null;
}

Expand Down
8 changes: 7 additions & 1 deletion src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -1498,16 +1498,18 @@ protected function extendCanUnpublish()
*
* @param Member $member
* @return bool
* @deprecated 5.3.0 Use canDelete() instead.
*/
public function canArchive($member = null)
{
Deprecation::notice('5.3.0', 'Use canDelete() instead.');
if (!$member) {
$member = Security::getCurrentUser();
}

// Standard mechanism for accepting permission changes from extensions
$owner = $this->owner;
$extended = $owner->extendedCan('canArchive', $member);
$extended = Deprecation::withNoReplacement(fn() => $owner->extendedCan('canArchive', $member));
if ($extended !== null) {
return $extended;
}
Expand All @@ -1530,8 +1532,12 @@ public function canArchive($member = null)
return true;
}

/**
* @deprecated 5.3.0 Will be removed without equivalent functionality.
*/
protected function extendCanArchive()
{
Deprecation::notice('5.3.0', 'Will be removed without equivalent functionality.');
// Prevent canArchive() extending itself
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions src/VersionedGridFieldItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
Expand Down Expand Up @@ -118,7 +119,7 @@ public function doArchive($data, $form)
{
/** @var Versioned|DataObject $record */
$record = $this->getRecord();
if (!$record->canArchive()) {
if (!Deprecation::withNoReplacement(fn() => $record->canArchive())) {
return $this->httpError(403);
}

Expand Down Expand Up @@ -293,7 +294,7 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions)
$canPublish = $record->canPublish();
$canUnpublish = $record->canUnpublish();
$canEdit = $record->canEdit();
$canArchive = $record->canArchive();
$canArchive = Deprecation::withNoReplacement(fn() => $record->canArchive());

// "save", supports an alternate state that is still clickable, but notifies the user that the action is not needed.
$noChangesClasses = 'btn-outline-primary font-icon-tick';
Expand Down

0 comments on commit 09e2d35

Please sign in to comment.