silverstripe-subsites/code/model/RelatedPageLink.php

90 lines
3.0 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',
);
2012-07-10 15:43:53 +02:00
public static $summary_fields=array(
'RelatedPageAdminLink' => 'Page',
'AbsoluteLink' => 'URL',
);
2010-03-01 04:01:50 +01:00
function getCMSFields() {
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
2012-03-25 18:35:01 +02:00
if(!$subsites) $subsites = new ArrayList();
if(Subsite::hasMainSitePermission(null, array("CMS_ACCESS_CMSMain"))) {
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", true);
}
2010-03-01 04:01:50 +01:00
if($subsites->Count()) {
$subsiteSelectionField = new DropdownField(
"CopyContentFromID_SubsiteID",
"Subsite",
$subsites->map('ID', 'Title'),
2010-03-01 04:01:50 +01:00
($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"
);
2010-03-31 00:50:37 +02:00
if (isset($_GET['RelatedPageID_SubsiteID'])) $pageSelectionField->setSubsiteID($_GET['RelatedPageID_SubsiteID']);
2010-03-01 04:01:50 +01:00
$pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
2012-03-25 18:35:01 +02:00
if($subsites->Count()) $fields = new FieldList($subsiteSelectionField, $pageSelectionField);
else $fields = new FieldList($pageSelectionField);
2010-03-01 04:01:50 +01:00
return $fields;
}
function RelatedPageAdminLink($master = false) {
2010-03-21 23:32:22 +01:00
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
$otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID) : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
if(!$page || !$otherPage) return;
// Use cmsEditlink only when moving between different pages in the same subsite.
$classClause = ($page->SubsiteID == $otherPage->SubsiteID) ? ' class="cmsEditlink"' : '';
return '<a href="admin/pages/edit/show/' . $page->ID . "\"$classClause>" . Convert::raw2xml($page->Title) . '</a>';
2010-03-01 04:01:50 +01:00
}
function AbsoluteLink($master = false) {
2010-03-21 23:32:22 +01:00
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
if(!$page) return;
$url = $page->AbsoluteLink();
}
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
}