Skip to content

Commit

Permalink
BUGFIX Added support for $fields parameter in CMSMain->getEditForm(),…
Browse files Browse the repository at this point in the history
… don't require 'ClassName' field in save() as its not included in getCMSFields() any longer.
  • Loading branch information
chillu committed Apr 28, 2011
1 parent bb4dbaa commit 8af9c54
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions code/controller/CMSMain.php
Expand Up @@ -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();

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -544,16 +546,18 @@ 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
if (isset($data['publish']) && $data['publish'] == 1) {
$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',
Expand All @@ -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'));

Expand Down

0 comments on commit 8af9c54

Please sign in to comment.