-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension to correctly support element preview
- Loading branch information
Michal Kleiner
committed
Jun 21, 2023
1 parent
b855a55
commit a052bfd
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Subsites\Extensions; | ||
|
||
use SilverStripe\Control\HTTP; | ||
use SilverStripe\ORM\DataExtension; | ||
|
||
/** | ||
* Extension for the BaseElement object to add subsites support for CMS previews | ||
*/ | ||
class BaseElementSubsites extends DataExtension | ||
{ | ||
/** | ||
* Set SubsiteID to avoid errors when a page doesn't exist on the CMS domain. | ||
* | ||
* @param string &$link | ||
* @param string|null $action | ||
* @return string | ||
*/ | ||
public function updatePreviewLink(&$link) | ||
{ | ||
// Get subsite ID from the element or from its page. Defaults to 0 automatically. | ||
$subsiteID = $this->owner->SubsiteID; | ||
if (is_null($subsiteID)) { | ||
$page = $this->owner->getPage(); | ||
if ($page) { | ||
$subsiteID = $page->SubsiteID; | ||
} | ||
} | ||
|
||
$link = HTTP::setGetVar('SubsiteID', intval($subsiteID), $link); | ||
} | ||
} |