silverstripe-subsites/code/RelatedPageLink.php

82 lines
2.4 KiB
PHP
Raw Normal View History

2010-03-01 04:01:50 +01:00
<?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(
'RelatedPage' => 'SiteTree',
// Note: The *last* matching has_one relation to SiteTree is used as the link field for the
// has_many (RelatedPages) on SiteTree. This isn't obvious and the framework could be
// extended in a future version to allow for explicit selection of a has_one relation to
// bind a has_many to.
2010-03-01 04:01:50 +01:00
'MasterPage' => 'SiteTree',
);
function getCMSFields() {
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", true);
2010-03-01 04:01:50 +01:00
if(!$subsites) $subsites = new DataObjectSet();
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 (isset($_GET['TreeDropdownField_ComplexTableField_Popup_AddForm_RelatedPageID_SubsiteID'])) {
$pageSelectionField->setSubsiteID($_GET['TreeDropdownField_ComplexTableField_Popup_AddForm_RelatedPageID_SubsiteID']);
}
2010-03-01 04:01:50 +01:00
$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="cmsEditlink">' . Convert::raw2xml($this->RelatedPage()->Title) . '</a>';
2010-03-01 04:01:50 +01:00
}
function AbsoluteLink() {
$url = $this->RelatedPage()->AbsoluteLink();
return '<a href="' . Convert::raw2att($url) .'" class="externallink">' . Convert::raw2xml($url) . '</a>';
}
function canView($member = null) {
return $this->MasterPage()->canView($member);
}
function canEdit($member = null) {
return $this->MasterPage()->canView($member);
}
function canDelete($member = null) {
return $this->MasterPage()->canDelete($member);
}
2010-03-01 04:01:50 +01:00
}
?>