Skip to content

Commit

Permalink
FIX Don't rely on session for current record ID (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Dec 12, 2024
1 parent b501926 commit 6cccd25
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Extensions/ShareDraftContentControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 6cccd25

Please sign in to comment.