From 62783c75a9568b0c22d504d145b3aa9d1f5995b3 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 27 Aug 2012 18:20:56 +0200 Subject: [PATCH] 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. --- code/controllers/CMSMain.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index edd62a82..dccb354c 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -574,17 +574,18 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $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')); } @@ -615,7 +616,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $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'));