BUG Prevent overwriting of draft/live preview form fields

By renaming fields to "StageLink" and "LiveLink",
which means they don't get influenced by the model getters
on Form->loadDataFrom(). Its also a more accurate
name for the field value, since it contains a full (nested) URL
rather than just a segment. Only used internally, so no API change.
This commit is contained in:
Ingo Schommer 2012-08-27 18:20:56 +02:00
parent 11b85e988e
commit 62783c75a9

View File

@ -574,17 +574,18 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$fields->push($idField = new HiddenField("ID", false, $id)); $fields->push($idField = new HiddenField("ID", false, $id));
// Necessary for different subsites // Necessary for different subsites
$fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
$fields->push($liveURLField = new HiddenField("LiveURLSegment")); $fields->push($liveURLField = new HiddenField("LiveLink"));
$fields->push($stageURLField = new HiddenField("StageURLSegment")); $fields->push($stageURLField = new HiddenField("StageLink"));
$fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle));
$fields->push(new HiddenField('Sort','', $record->Sort)); $fields->push(new HiddenField('Sort','', $record->Sort));
if($record->ID && is_numeric( $record->ID ) ) { if($record->ID && is_numeric( $record->ID ) ) {
$liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = $record->ID"); $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = $record->ID");
if($liveRecord) $liveURLField->setValue($liveRecord->AbsoluteLink()); if($liveRecord) {
$liveURLField->setValue(Controller::join_links($liveRecord->AbsoluteLink(), '?stage=Live'));
}
} }
if(!$deletedFromStage) { if(!$deletedFromStage) {
$stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage')); $stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage'));
} }
@ -615,7 +616,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$form = new Form($this, "EditForm", $fields, $actions, $validator); $form = new Form($this, "EditForm", $fields, $actions, $validator);
$form->loadDataFrom($record); $form->loadDataFrom($record);
$stageURLField->setValue(Controller::join_links($record->getStageURLSegment(), '?stage=Stage'));
$form->disableDefaultAction(); $form->disableDefaultAction();
$form->addExtraClass('cms-edit-form'); $form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));