NEW SiteTree->PreviewLink() for fine grained URL control

This commit is contained in:
Ingo Schommer 2013-01-14 12:06:34 +01:00
parent f9504ee983
commit 76aeec70e7
2 changed files with 16 additions and 4 deletions

View File

@ -246,7 +246,7 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
}
public function getLink() {
return Controller::join_links($this->record->AbsoluteLink(), '?stage=Stage');
return Controller::join_links($this->record->PreviewLink(), '?stage=Stage');
}
public function canView($member = null) {
@ -299,7 +299,7 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
}
public function getLink() {
return Controller::join_links($this->record->AbsoluteLink(), '?stage=Live');
return Controller::join_links($this->record->PreviewLink(), '?stage=Live');
}
public function canView($member = null) {
@ -333,7 +333,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
static $priority = 40;
public function getHTML() {
$this->recordLink = $this->record->AbsoluteLink();
$this->recordLink = $this->record->PreviewLink();
return "<a class=\"ss-ui-button\" href=\"$this->recordLink?archiveDate={$this->record->LastEdited}\" target=\"_blank\">". _t('ContentController.ARCHIVEDSITE', 'Preview version') ."</a>";
}
@ -350,7 +350,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
}
public function getLink() {
return $this->record->AbsoluteLink() . '?archiveDate=' . $this->record->LastEdited;
return $this->record->PreviewLink() . '?archiveDate=' . $this->record->LastEdited;
}
public function canView($member = null) {

View File

@ -412,6 +412,18 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
return Director::absoluteURL($this->Link($action));
}
}
/**
* Base link used for previewing. Defaults to absolute URL,
* in order to account for domain changes, e.g. on multi site setups.
* Does not contain hints about the stage, see {@link SilverStripeNavigator} for details.
*
* @param string $action See {@link Link()}
* @return string
*/
public function PreviewLink($action = null) {
return $this->AbsoluteLink($action);
}
/**
* Return the link for this {@link SiteTree} object relative to the SilverStripe root.