diff --git a/src/Extensions/ShareDraftContentControllerExtension.php b/src/Extensions/ShareDraftContentControllerExtension.php index c205f37..614ef23 100644 --- a/src/Extensions/ShareDraftContentControllerExtension.php +++ b/src/Extensions/ShareDraftContentControllerExtension.php @@ -4,6 +4,7 @@ use SilverStripe\Control\Controller; use SilverStripe\Core\Extension; +use SilverStripe\Security\Member; use SilverStripe\Security\Security; /** @@ -24,17 +25,28 @@ class ShareDraftContentControllerExtension extends Extension public function MakeShareDraftLink() { if ($member = Security::getCurrentUser()) { - if ($this->owner->hasMethod('CurrentPage') && $this->owner->CurrentPage()->canView($member)) { - return $this->owner->CurrentPage()->ShareTokenLink(); - } - if ($this->owner->hasMethod('canView') && $this->owner->canView($member)) { - return $this->owner->ShareTokenLink(); + if ($this->owner->hasMethod('CurrentPage')) { + $link = $this->getShareTokenLink($this->owner->CurrentPage(), $member); + } elseif ($this->owner->hasMethod('currentRecord')) { + $link = $this->getShareTokenLink($this->owner->currentRecord(), $member); } + $link ??= $this->getShareTokenLink($this->owner, $member); + } + if ($link) { + return $link; } return Security::permissionFailure(); } + private function getShareTokenLink(object $record, Member $member): ?string + { + if ($record->hasMethod('canView') && $record->canView($member)) { + return $record->ShareTokenLink(); + } + return null; + } + /** * @return string */ diff --git a/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss b/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss index 625da5a..6a47657 100644 --- a/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss +++ b/templates/SilverStripe/Admin/Includes/LeftAndMain_ViewModeSelector.ss @@ -2,7 +2,7 @@ <%-- Placeholder is re-rendered by the ShareDraftContent React component --%>