mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This DataObject only exists to provide a link between related pages.
|
|
* Unfortunately, there is no way to provide a decent GUI otherwise.
|
|
*/
|
|
class RelatedPageLink extends DataObject {
|
|
static $db = array(
|
|
);
|
|
|
|
static $has_one = array(
|
|
'MasterPage' => 'SiteTree',
|
|
'RelatedPage' => 'SiteTree'
|
|
);
|
|
|
|
function getCMSFields() {
|
|
$subsites = Subsite::getSubsitesForMember();
|
|
if(!$subsites) $subsites = new DataObjectSet();
|
|
if(Subsite::hasMainSitePermission()) {
|
|
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
|
|
}
|
|
|
|
if($subsites->Count()) {
|
|
$subsiteSelectionField = new DropdownField(
|
|
"CopyContentFromID_SubsiteID",
|
|
"Subsite",
|
|
$subsites->toDropdownMap('ID', 'Title'),
|
|
($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
|
|
);
|
|
}
|
|
|
|
// Setup the linking to the original page.
|
|
$pageSelectionField = new SubsitesTreeDropdownField(
|
|
"RelatedPageID",
|
|
_t('VirtualPage.CHOOSE', "Choose a page to link to"),
|
|
"SiteTree",
|
|
"ID",
|
|
"MenuTitle"
|
|
);
|
|
|
|
if(Controller::curr()->getRequest()) {
|
|
$subsiteID = Controller::curr()->getRequest()->getVar('TreeDropdownField_ComplexTableField_Popup_AddForm_RelatedPageID_SubsiteID');
|
|
$pageSelectionField->setSubsiteID($subsiteID);
|
|
}
|
|
|
|
$pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
|
|
|
|
if($subsites->Count()) {
|
|
$fields = new FieldSet(
|
|
$subsiteSelectionField,
|
|
$pageSelectionField
|
|
);
|
|
} else {
|
|
$fields = new FieldSet(
|
|
$pageSelectionField
|
|
);
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
function RelatedPageAdminLink() {
|
|
return '<a href="admin/show/' . $this->RelatedPage()->ID . '" class="externallink" >' . Convert::raw2xml($this->RelatedPage()->Title) . '</a>';
|
|
}
|
|
}
|
|
|
|
?>
|