Skip to content

Commit

Permalink
FIX Allow empty PreviewURLs for CMSPreviewable objects
Browse files Browse the repository at this point in the history
An empty PreviewURL will result in the "no preview available" message
displaying instead of a 404 error.
  • Loading branch information
GuySartorelli committed May 6, 2022
1 parent 1563ab3 commit c02549c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions code/Controllers/SilverStripeNavigatorItem_ArchiveLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public function getMessage()

public function getLink()
{
return Controller::join_links(
$this->record->PreviewLink(),
'?archiveDate=' . urlencode($this->record->LastEdited ?? '')
);
$link = $this->record->PreviewLink();
return $link ? Controller::join_links($link, '?archiveDate=' . urlencode($this->record->LastEdited ?? '')) : '';
}

public function canView($member = null)
Expand All @@ -62,6 +60,7 @@ public function canView($member = null)
&& $this->isArchived()
// Don't follow redirects in preview, they break the CMS editing form
&& !($record instanceof RedirectorPage)
&& $this->getLink()
);
}

Expand Down
4 changes: 3 additions & 1 deletion code/Controllers/SilverStripeNavigatorItem_LiveLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function getMessage()

public function getLink()
{
return Controller::join_links($this->getLivePage()->PreviewLink(), '?stage=Live');
$link = $this->getLivePage()->PreviewLink();
return $link ? Controller::join_links($link, '?stage=Live') : '';
}

public function canView($member = null)
Expand All @@ -60,6 +61,7 @@ public function canView($member = null)
&& $this->showLiveLink()
&& $record->hasStages()
&& $this->getLivePage()
&& $this->getLink()
);
}

Expand Down
7 changes: 6 additions & 1 deletion code/Controllers/SilverStripeNavigatorItem_StageLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public function getMessage()
public function getLink()
{
$date = Versioned::current_archived_date();
$link = $this->record->PreviewLink();
if (!$link) {
return '';
}
return Controller::join_links(
$this->record->PreviewLink(),
$link,
'?stage=Stage',
$date ? '?archiveDate=' . $date : null
);
Expand All @@ -66,6 +70,7 @@ public function canView($member = null)
&& $this->showStageLink()
&& $record->hasStages()
&& $this->getDraftPage()
&& $this->getLink()
);
}

Expand Down
3 changes: 2 additions & 1 deletion code/Controllers/SilverStripeNavigatorItem_Unversioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getHTML()

public function getLink()
{
return $this->getRecord()->PreviewLink();
return $this->getRecord()->PreviewLink() ?? '';
}

public function getTitle()
Expand All @@ -42,6 +42,7 @@ public function canView($member = null)
return (
!$this->getRecord()->hasExtension(Versioned::class)
&& $this->showUnversionedLink()
&& $this->getLink()
);
}

Expand Down

0 comments on commit c02549c

Please sign in to comment.