diff --git a/code/controller/CMSMain.php b/code/controller/CMSMain.php index a65fb43568..94bf8dc8a4 100755 --- a/code/controller/CMSMain.php +++ b/code/controller/CMSMain.php @@ -398,9 +398,11 @@ public function getRecord($id) { } /** - * Calls {@link SiteTree->getCMSFields()} + * @param Int $id + * @param FieldSet $fields + * @return Form */ - public function getEditForm($id = null) { + public function getEditForm($id = null, $fields = null) { // Include JavaScript to ensure HtmlEditorField works. HtmlEditorField::include_js(); @@ -411,7 +413,7 @@ public function getEditForm($id = null) { $record = $this->getRecord($id); if($record && !$record->canView()) return Security::permissionFailure($this); - $fields = $form->Fields(); + if(!$fields) $fields = $form->Fields(); $actions = $form->Actions(); if($record) { @@ -533,7 +535,7 @@ public function save($data, $form) { $record->writeWithoutVersion(); // Update the class instance if necessary - if($data['ClassName'] != $record->ClassName) { + if(isset($data['ClassName']) && $data['ClassName'] != $record->ClassName) { $newClassName = $record->ClassName; // The records originally saved attribute was overwritten by $form->saveInto($record) before. // This is necessary for newClassInstance() to work as expected, and trigger change detection @@ -544,7 +546,7 @@ public function save($data, $form) { } // save form data into record - $form->saveInto($record, true); + $form->saveInto($record); $record->write(); // If the 'Save & Publish' button was clicked, also publish the page @@ -552,8 +554,10 @@ public function save($data, $form) { $record->doPublish(); // Update classname with original and get new instance (see above for explanation) - $record->setClassName($data['ClassName']); - $publishedRecord = $record->newClassInstance($record->ClassName); + if(isset($data['ClassName'])) { + $record->setClassName($data['ClassName']); + $publishedRecord = $record->newClassInstance($record->ClassName); + } $this->response->addHeader( 'X-Status', @@ -564,12 +568,12 @@ public function save($data, $form) { PR_MEDIUM, 'Status message after publishing a page, showing the page title' ), - $publishedRecord->Title + $record->Title ) ); // Reload form, data and actions might have changed - $form = $this->getEditForm($publishedRecord->ID); + $form = $this->getEditForm($record->ID); } else { $this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));