From cf6f00816265724637bab6055c5037013f86cfde Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Wed, 11 Dec 2024 13:40:03 +1300 Subject: [PATCH] FIX Don't rely on session for current record ID --- .../ShareDraftContentControllerExtension.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Extensions/ShareDraftContentControllerExtension.php b/src/Extensions/ShareDraftContentControllerExtension.php index 9468e18..f7f1b03 100644 --- a/src/Extensions/ShareDraftContentControllerExtension.php +++ b/src/Extensions/ShareDraftContentControllerExtension.php @@ -53,9 +53,27 @@ private function getShareTokenLink(object $record, Member $member): ?string */ public function getShareDraftLinkAction() { - if ($this->owner->config()->get('url_segment')) { - return $this->owner->Link('MakeShareDraftLink'); + $owner = $this->getOwner(); + if (!$owner->config()->get('url_segment')) { + return ''; } - return ''; + $id = $this->getRecordID(); + if (!$id) { + return ''; + } + return $owner->Link(Controller::join_links('MakeShareDraftLink', $id)); + } + + private function getRecordID(): ?int + { + $owner = $this->getOwner(); + if ($owner->hasMethod('currentRecordID')) { + return $owner->currentRecordID(); + } + // Could be a non-LeftAndMain controller, since the extension is applied directly to Controller + if ($owner->hasMethod('CurrentPage')) { + return $owner->CurrentPage()?->ID; + } + return null; } }