Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUGFIX Reconstruct form before returning from LeftAndMain and CMSMain…

… controller actions, in order to avoid stale form fields or form actions (e.g. after hitting CMSMain->unpublish(), the 'unpublish' FormAction has to be removed from the existing form)
  • Loading branch information...
commit 4eac937da6df314944faa6a82a5f3a4e545bd997 1 parent 824f745
@chillu chillu authored
Showing with 22 additions and 13 deletions.
  1. +21 −12 code/CMSMain.php
  2. +1 −1  code/LeftAndMain.php
View
33 code/CMSMain.php
@@ -490,8 +490,8 @@ public function getEditForm($id = null) {
return $this->RootForm();
} else if($id) {
return new Form($this, "EditForm", new FieldSet(
- new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldSet());
-
+ new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldSet()
+ );
}
}
@@ -574,13 +574,14 @@ public function save($data, $form) {
$publishedRecord->Title
)
);
-
- $form->loadDataFrom($publishedRecord);
+
+ // Reload form, data and actions might have changed
+ $form = $this->getEditForm($publishedRecord->ID);
} else {
$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
- // write process might've changed the record, so we reload before returning
- $form->loadDataFrom($record);
+ // Reload form, data and actions might have changed
+ $form = $this->getEditForm($record->ID);
}
return $form->formHtmlContent();
@@ -995,18 +996,20 @@ function publish($data, $form) {
}
function unpublish($data, $form) {
- $page = DataObject::get_by_id("SiteTree", $data['ID']);
+ $className = $this->stat('tree_class');
+ $record = DataObject::get_by_id($className, $data['ID']);
- if($page && !$page->canDeleteFromLive()) return Security::permissionFailure($this);
+ if($record && !$record->canDeleteFromLive()) return Security::permissionFailure($this);
- $page->doUnpublish();
+ $record->doUnpublish();
$this->response->addHeader(
'X-Status',
- sprintf(_t('CMSMain.REMOVEDPAGE',"Removed '%s' from the published site"),$page->Title)
+ sprintf(_t('CMSMain.REMOVEDPAGE',"Removed '%s' from the published site"),$record->Title)
);
- $form->loadDataFrom($page);
+ // Reload form, data and actions might have changed
+ $form = $this->getEditForm($record->ID);
return $form->formHtmlContent();
}
@@ -1487,7 +1490,9 @@ function restore($data, $form) {
)
);
- $form = $this->getEditForm($id);
+ // Reload form, data and actions might have changed
+ $form = $this->getEditForm($restoredPage->ID);
+
return $form->formHtmlContent();
}
@@ -1509,7 +1514,9 @@ function duplicate($request) {
$newPage->write();
}
+ // Reload form, data and actions might have changed
$form = $this->getEditForm($newPage->ID);
+
return $form->formHtmlContent();
} else {
user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING);
@@ -1528,7 +1535,9 @@ function duplicatewithchildren($request) {
$newPage = $page->duplicateWithChildren();
+ // Reload form, data and actions might have changed
$form = $this->getEditForm($newPage->ID);
+
return $form->formHtmlContent();
} else {
user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING);
View
2  code/LeftAndMain.php
@@ -614,7 +614,7 @@ public function save($data, $form) {
$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
// write process might've changed the record, so we reload before returning
- $form->loadDataFrom($record);
+ $form = $this->getEditForm($record->ID);
return $form->formHtmlContent();
}
Please sign in to comment.
Something went wrong with that request. Please try again.