Skip to content

Commit

Permalink
BUG Prevent overwriting of draft/live preview form fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chillu committed Aug 27, 2012
1 parent 11b85e9 commit 62783c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions code/controllers/CMSMain.php
Expand Up @@ -574,17 +574,18 @@ public function getEditForm($id = null, $fields = null) {
$fields->push($idField = new HiddenField("ID", false, $id));
// Necessary for different subsites
$fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
$fields->push($liveURLField = new HiddenField("LiveURLSegment"));
$fields->push($stageURLField = new HiddenField("StageURLSegment"));
$fields->push($liveURLField = new HiddenField("LiveLink"));
$fields->push($stageURLField = new HiddenField("StageLink"));
$fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle));

$fields->push(new HiddenField('Sort','', $record->Sort));

if($record->ID && is_numeric( $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) {
$stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage'));
}
Expand Down Expand Up @@ -615,7 +616,6 @@ public function getEditForm($id = null, $fields = null) {

$form = new Form($this, "EditForm", $fields, $actions, $validator);
$form->loadDataFrom($record);
$stageURLField->setValue(Controller::join_links($record->getStageURLSegment(), '?stage=Stage'));
$form->disableDefaultAction();
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
Expand Down

0 comments on commit 62783c7

Please sign in to comment.