-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Deprecate Versioned::canArchive() #461
API Deprecate Versioned::canArchive() #461
Conversation
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extendedCan()
will result in calling extendCanArchive()
which is also deprecated, so we need to wrap this call too.
/** | ||
* @deprecated 5.3.0 Will be removed without equivalent functionality. | ||
*/ | ||
protected function extendCanArchive() | ||
{ | ||
Deprecation::notice('5.3.0', 'Will be removed without equivalent functionality.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected
methods are part of our definition of public API so we need to deprecate this even though nobody is likely to be calling it directly and it's effectively a no-op.
77003f3
to
3eefaa5
Compare
src/GridFieldArchiveAction.php
Outdated
if (!$record->hasMethod('canArchive') || !$record->canArchive()) { | ||
if (!$record->hasMethod('canArchive')) { | ||
return null; | ||
} | ||
$canArchive = !Deprecation::withNoReplacement(fn() => $record->canArchive()); | ||
if ($canArchive) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to separate these conditions to comply with #461 (comment)
3eefaa5
to
07851ca
Compare
For versioned records, there is no concept of "deleting" the record - it's either being archived, unpublished, or in rare cases removed from draft but left published.
Previously the
canDelete()
method has been used to check if a record can be removed from draft specifically for versioned records - which is such a rare edge case it almost doesn't bare thinking about, especially given there's no way to do that purely by interacting with the UI, nor with the web API endpoints available in core or supported modules.Instead,
canDelete()
should be used to check if the record can be archived. This reduces cognitive load for developers and is a step towards simplifying the overly-complex versioning system. This is also in keeping with other mechanisms, such ascascade_deletes
which cascades archiving for versioned records.Issue
canArchive()
method for CMS 6 #447