Skip to content

Commit

Permalink
FIX Use PreviewLink of the owner object to preview blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 11, 2022
1 parent 97ba7b0 commit 3910b4e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public function AbsoluteLink($action = null)

/**
* @param string|null $action
* @return string
* @return string|null
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \SilverStripe\ORM\ValidationException
*/
Expand All @@ -721,16 +721,27 @@ public function Link($action = null)

/**
* @param string|null $action
* @return string
* @return string|null
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \SilverStripe\ORM\ValidationException
*/
public function PreviewLink($action = null)
{
$action = $action . '?ElementalPreview=' . mt_rand();
$link = $this->Link($action);
$this->extend('updatePreviewLink', $link);
$link = null;
if ($page = $this->getPage()) {
if (ClassInfo::hasMethod($page, 'Link')) {
$link = $page->Link($action);
} elseif ($page instanceof CMSPreviewable) {
$link = $page->PreviewLink($action);
}
if ($link) {
// The ElementalPreview getvar is used in ElementalPageExtension
// The anchor must be at the end of the URL to function correctly
$link .= '?ElementalPreview=' . mt_rand() . '#' . $this->getAnchor();
}
}

$this->extend('updatePreviewLink', $link);
return $link;
}

Expand Down

0 comments on commit 3910b4e

Please sign in to comment.