mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
2ef72b374c
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
171 lines
6.0 KiB
PHP
171 lines
6.0 KiB
PHP
<?php
|
|
class SubsitesVirtualPage extends VirtualPage {
|
|
public static $db = array(
|
|
'CustomMetaTitle' => 'Varchar(255)',
|
|
'CustomMetaKeywords' => 'Varchar(255)',
|
|
'CustomMetaDescription' => 'Text',
|
|
'CustomExtraMeta' => 'HTMLText'
|
|
);
|
|
|
|
public function getCMSFields() {
|
|
$fields = parent::getCMSFields();
|
|
|
|
$subsites = DataObject::get('Subsite');
|
|
if(!$subsites) {
|
|
$subsites = new ArrayList();
|
|
}else {
|
|
$subsites=ArrayList::create($subsites->toArray());
|
|
}
|
|
|
|
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
|
|
|
|
$subsiteSelectionField = new DropdownField(
|
|
"CopyContentFromID_SubsiteID",
|
|
"Subsite",
|
|
$subsites->map('ID', 'Title'),
|
|
($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
|
|
);
|
|
$fields->addFieldToTab(
|
|
'Root.Main',
|
|
$subsiteSelectionField,
|
|
'CopyContentFromID'
|
|
);
|
|
|
|
// Setup the linking to the original page.
|
|
$pageSelectionField = new SubsitesTreeDropdownField(
|
|
"CopyContentFromID",
|
|
_t('VirtualPage.CHOOSE', "Choose a page to link to"),
|
|
"SiteTree",
|
|
"ID",
|
|
"MenuTitle"
|
|
);
|
|
|
|
if(Controller::has_curr() && Controller::curr()->getRequest()) {
|
|
$subsiteID = Controller::curr()->getRequest()->postVar('CopyContentFromID_SubsiteID');
|
|
$pageSelectionField->setSubsiteID($subsiteID);
|
|
}
|
|
$fields->replaceField('CopyContentFromID', $pageSelectionField);
|
|
|
|
// Create links back to the original object in the CMS
|
|
if($this->CopyContentFromID) {
|
|
$editLink = "admin/page/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID;
|
|
$linkToContent = "
|
|
<a class=\"cmsEditlink\" href=\"$editLink\">" .
|
|
_t('VirtualPage.EDITCONTENT', 'Click here to edit the content') .
|
|
"</a>";
|
|
$fields->removeByName("VirtualPageContentLinkLabel");
|
|
$fields->addFieldToTab(
|
|
"Root.Main",
|
|
$linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent),
|
|
'Title'
|
|
);
|
|
$linkToContentLabelField->setAllowHTML(true);
|
|
}
|
|
|
|
|
|
$fields->addFieldToTab('Root.Metadata', new TextField('CustomMetaTitle', 'Title (overrides inherited value from the source)'), 'MetaTitle');
|
|
$fields->addFieldToTab('Root.Metadata', new TextareaField('CustomMetaKeywords', 'Keywords (overrides inherited value from the source)'), 'MetaKeywords');
|
|
$fields->addFieldToTab('Root.Metadata', new TextareaField('CustomMetaDescription', 'Description (overrides inherited value from the source)'), 'MetaDescription');
|
|
$fields->addFieldToTab('Root.Metadata', new TextField('CustomExtraMeta', 'Custom Meta Tags (overrides inherited value from the source)'), 'ExtraMeta');
|
|
|
|
return $fields;
|
|
}
|
|
|
|
public function getVirtualFields() {
|
|
$fields = parent::getVirtualFields();
|
|
foreach($fields as $k => $v) {
|
|
if($v == 'SubsiteID') unset($fields[$k]);
|
|
}
|
|
|
|
foreach(self::$db as $field => $type) if (in_array($field, $fields)) unset($fields[array_search($field, $fields)]);
|
|
|
|
return $fields;
|
|
}
|
|
|
|
public function syncLinkTracking() {
|
|
$oldState = Subsite::$disable_subsite_filter;
|
|
Subsite::$disable_subsite_filter = true;
|
|
if ($this->CopyContentFromID) $this->HasBrokenLink = DataObject::get_by_id('SiteTree', $this->CopyContentFromID) ? false : true;
|
|
Subsite::$disable_subsite_filter = $oldState;
|
|
}
|
|
|
|
public function onBeforeWrite() {
|
|
parent::onBeforeWrite();
|
|
|
|
if($this->CustomMetaTitle) $this->MetaTitle = $this->CustomMetaTitle;
|
|
else {
|
|
$this->MetaTitle = $this->ContentSource()->MetaTitle ? $this->ContentSource()->MetaTitle : $this->MetaTitle;
|
|
}
|
|
if($this->CustomMetaKeywords) $this->MetaKeywords = $this->CustomMetaKeywords;
|
|
else {
|
|
$this->MetaKeywords = $this->ContentSource()->MetaKeywords ? $this->ContentSource()->MetaKeywords : $this->MetaKeywords;
|
|
}
|
|
if($this->CustomMetaDescription) $this->MetaDescription = $this->CustomMetaDescription;
|
|
else {
|
|
$this->MetaDescription = $this->ContentSource()->MetaDescription ? $this->ContentSource()->MetaDescription : $this->MetaDescription;
|
|
}
|
|
if($this->CustomExtraMeta) $this->ExtraMeta = $this->CustomExtraMeta;
|
|
else {
|
|
$this->ExtraMeta = $this->ContentSource()->ExtraMeta ? $this->ContentSource()->ExtraMeta : $this->ExtraMeta;
|
|
}
|
|
}
|
|
|
|
public function validURLSegment() {
|
|
$isValid = parent::validURLSegment();
|
|
|
|
// Veto the validation rules if its false. In this case, some logic
|
|
// needs to be duplicated from parent to find out the exact reason the validation failed.
|
|
if(!$isValid) {
|
|
$IDFilter = ($this->ID) ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null;
|
|
$parentFilter = null;
|
|
|
|
if(self::nested_urls()) {
|
|
if($this->ParentID) {
|
|
$parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID";
|
|
} else {
|
|
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
|
|
}
|
|
}
|
|
|
|
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
|
Subsite::$disable_subsite_filter = true;
|
|
$existingPage = DataObject::get_one(
|
|
'SiteTree',
|
|
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
|
|
false // disable cache, it doesn't include subsite status in the key
|
|
);
|
|
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
|
|
$existingPageInSubsite = DataObject::get_one(
|
|
'SiteTree',
|
|
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
|
|
false // disable cache, it doesn't include subsite status in the key
|
|
);
|
|
|
|
// If URL has been vetoed because of an existing page,
|
|
// be more specific and allow same URLSegments in different subsites
|
|
$isValid = !($existingPage && $existingPageInSubsite);
|
|
}
|
|
|
|
return $isValid;
|
|
}
|
|
}
|
|
|
|
class SubsitesVirtualPage_Controller extends VirtualPage_Controller {
|
|
|
|
public function reloadContent() {
|
|
$this->failover->copyFrom($this->failover->CopyContentFrom());
|
|
$this->failover->write();
|
|
return;
|
|
}
|
|
|
|
public function init(){
|
|
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
|
Subsite::$disable_subsite_filter = true;
|
|
|
|
parent::init();
|
|
|
|
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
|
|
}
|
|
}
|
|
?>
|