FIX Allow empty PreviewURLs for CMSPreviewable objects

An empty PreviewURL will result in the "no preview available" message
displaying instead of a 404 error.
This commit is contained in:
Guy Sartorelli 2022-05-04 12:43:23 +12:00
parent 1563ab3fcf
commit c02549cf30
4 changed files with 14 additions and 7 deletions

View File

@ -46,10 +46,8 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
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)
@ -62,6 +60,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
&& $this->isArchived()
// Don't follow redirects in preview, they break the CMS editing form
&& !($record instanceof RedirectorPage)
&& $this->getLink()
);
}

View File

@ -48,7 +48,8 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
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)
@ -60,6 +61,7 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
&& $this->showLiveLink()
&& $record->hasStages()
&& $this->getLivePage()
&& $this->getLink()
);
}

View File

@ -50,8 +50,12 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem
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
);
@ -66,6 +70,7 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem
&& $this->showStageLink()
&& $record->hasStages()
&& $this->getDraftPage()
&& $this->getLink()
);
}

View File

@ -19,7 +19,7 @@ class SilverStripeNavigatorItem_Unversioned extends SilverStripeNavigatorItem
public function getLink()
{
return $this->getRecord()->PreviewLink();
return $this->getRecord()->PreviewLink() ?? '';
}
public function getTitle()
@ -42,6 +42,7 @@ class SilverStripeNavigatorItem_Unversioned extends SilverStripeNavigatorItem
return (
!$this->getRecord()->hasExtension(Versioned::class)
&& $this->showUnversionedLink()
&& $this->getLink()
);
}