mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
26b8f7dffe
Inform-merge: from the changeset: r32477: Merge 2.0-inform from trunk previously r32478: Merge 2.0-inform from trunk previously r32481: merge 2.0infom with lastes chunk r32483: merge 2.0infom with lastes chunk r33526: Final styling of all forms and combined communication form add/alter javascript for height adjustment of First / Second block r33580: styling for combined form communication in myinfom pages r33706: styling of combined form (communication) in Email r33881: made compatible to $extraClass r33885: added defaultVal r33887: fixed typo r34728: modified SmallFieldHolder?() r34729: added "validationError"-class r34914: WIP3866: Factfinder: Hide "self emplyed" block r34964: Change current plan upto TraumaInsurance? r35038: disabled friggin field focus r35230: #1032 Fixed hash-link insertion r35887: conditionally setting parameters in sourceID() - to avoid empty overrides r35892: Saving value in SQL-compatible format (YYYY-MM-DD instead of DD/MM/YYYY), with fallback for non-sql values (just passed through without conversion) r35928: Removed "create a" from PageType?-dropdown, sorting alphabetically, falling back to $singular_name r35990: branched off for membertablefield r35994: fix for membertablefield r36024: added array-condition needed for DMYDateField r36083: fix bug for compositeField -> dropDatalessField r36394: removed debug code r36826: change wrong indent format r36828: WIP 4262: Logging out of My Inform goes to blank page r36858: Fixed error caused in r12472 while merging to Session-class r37132: Merged partial changesets from branches/2.0-nzct, only adding childID to detailform when not in add-mode r40815: add an unsubscribe record when a member subscribe a newslettertype r41113: fix the bug described in http://support.silverstripe.com/info/ticket/31: CRM not showing search results r43226: fixed search (partial merge from trunk) r43268: merged createNewPassword() from trunk, was referencing a non-existinent global function randomString() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45473 467b73ca-7a2a-4603-9d3b-597d59a354a9
164 lines
4.6 KiB
PHP
Executable File
164 lines
4.6 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Virtual Page creates an instance of a page, with the same fields that the original page had, but readonly.
|
|
* This allows you can have a page in mulitple places in the site structure, with different children without duplicating the content
|
|
* Note: This Only duplicates $db fields and not the $has_one etc..
|
|
*/
|
|
class VirtualPage extends Page {
|
|
|
|
static $add_action = "Virtual page (another page's content)";
|
|
|
|
static $icon = array("cms/images/treeicons/page-shortcut-gold","file");
|
|
|
|
public static $virtualFields;
|
|
|
|
static $has_one = array(
|
|
"CopyContentFrom" => "SiteTree",
|
|
);
|
|
|
|
static $db = array(
|
|
"VersionID" => "Int",
|
|
);
|
|
|
|
/**
|
|
* Generates the array of fields required for the page type.
|
|
*/
|
|
function getVirtualFields() {
|
|
$nonVirtualFields = array(
|
|
"SecurityTypeID",
|
|
"OwnerID",
|
|
"AssignedToID",
|
|
"RequestedByID",
|
|
"URLSegment",
|
|
"Sort",
|
|
"Status",
|
|
'ShowInMenus',
|
|
'ShowInSearch'
|
|
);
|
|
|
|
$allFields = $this->db();
|
|
if($hasOne = $this->has_one()) foreach($hasOne as $link) $allFields[$link . 'ID'] = "Int";
|
|
foreach($allFields as $field => $type) {
|
|
if(!in_array($field, $nonVirtualFields)) $virtualFields[] = $field;
|
|
}
|
|
|
|
return $virtualFields;
|
|
}
|
|
|
|
function ContentSource() {
|
|
return $this->CopyContentFrom();
|
|
}
|
|
|
|
|
|
/**
|
|
* Generate the CMS fields from the fields from the original page.
|
|
*/
|
|
function getCMSFields($cms = null) {
|
|
$fields = parent::getCMSFields($cms);
|
|
|
|
// Setup the linking to the original page.
|
|
$copyContentFromField = new TreeDropdownField(
|
|
"CopyContentFromID",
|
|
_t('VirtualPage.CHOOSE', "Choose a page to link to"),
|
|
"SiteTree"
|
|
);
|
|
$copyContentFromField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
|
|
|
|
// Setup virtual fields
|
|
if($virtualFields = $this->getVirtualFields()) {
|
|
$roTransformation = new ReadonlyTransformation();
|
|
foreach($virtualFields as $virtualField) {
|
|
if($fields->dataFieldByName($virtualField))
|
|
$fields->replaceField($virtualField, $fields->dataFieldByName($virtualField)->transform($roTransformation));
|
|
}
|
|
}
|
|
|
|
// Add fields to the tab
|
|
$fields->addFieldToTab("Root.Content.Main",
|
|
new HeaderField(_t('VirtualPage.HEADER', "This is a virtual page")),
|
|
"Title"
|
|
);
|
|
$fields->addFieldToTab("Root.Content.Main", $copyContentFromField, "Title");
|
|
|
|
// Create links back to the original object in the CMS
|
|
if($this->CopyContentFromID) {
|
|
$linkToContent = "<a class=\"cmsEditlink\" href=\"admin/show/$this->CopyContentFromID\">" .
|
|
_t('VirtualPage.EDITCONTENT', 'click here to edit the content') . "</a>";
|
|
$fields->addFieldToTab("Root.Content.Main", new LabelField($linkToContent, null, true), "Title");
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
/**
|
|
* We have to change it to copy all the content from the original page first.
|
|
*/
|
|
function onBeforeWrite() {
|
|
// Don't do this stuff when we're publishing
|
|
if(!$this->extension_instances['Versioned']->migratingVersion) {
|
|
if(isset($this->changed['CopyContentFromID']) && $this->changed['CopyContentFromID']
|
|
&& $this->CopyContentFromID != 0 && $this->class == 'VirtualPage' ) {
|
|
$CopyContentFromID = $this->CopyContentFromID;
|
|
$source = DataObject::get_one("Sitetree","`Sitetree`.`ID`='$CopyContentFromID'");
|
|
$this->copyFrom($source);
|
|
$this->URLSegment = $source->URLSegment . '-' . $this->ID;
|
|
}
|
|
}
|
|
|
|
parent::onBeforeWrite();
|
|
}
|
|
/**
|
|
* Ensure we have an up-to-date version of everything.
|
|
*/
|
|
function copyFrom($source) {
|
|
if($source) {
|
|
foreach($this->getVirtualFields() AS $virtualField)
|
|
$this->$virtualField = $source->$virtualField;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @desc
|
|
*/
|
|
class VirtualPage_Controller extends Page_Controller {
|
|
|
|
/**
|
|
* Reloads the content if the version is different ;-)
|
|
*/
|
|
function reloadContent() {
|
|
$this->failover->copyFrom($this->failover->CopyContentFrom());
|
|
$this->failover->write();
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* When the virtualpage is loaded, check to see if the versions are the same
|
|
* if not, reload the content.
|
|
* NOTE: Virtual page must have a container object of subclass of sitetree.
|
|
* We can't load the content without an ID or record to copy it from.
|
|
*/
|
|
function init(){
|
|
if($this->record->ID){
|
|
if($this->record->VersionID != $this->failover->CopyContentFrom()->Version){
|
|
$this->reloadContent();
|
|
$this->VersionID = $this->failover->CopyContentFrom()->VersionID;
|
|
}
|
|
}
|
|
parent::init();
|
|
}
|
|
|
|
function loadcontentall() {
|
|
$pages = DataObject::get("VirtualPage");
|
|
foreach($pages as $page) {
|
|
$page->copyFrom($page->CopyContentFrom());
|
|
$page->write();
|
|
$page->publish("Stage", "Live");
|
|
echo "<li>Published $page->URLSegment";
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|