BUG Fix page history / settings forms

This commit is contained in:
Damian Mooyman 2017-04-26 18:13:48 +12:00
parent 475b733579
commit 000a5f7209
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

View File

@ -627,23 +627,25 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} }
/** /**
* @param int $id * @param int|SiteTree $idOrRecord ID of record or record instance
* @param FieldList $fields * @param FieldList $fields
* @return CMSForm * @return CMSForm
*/ */
public function getEditForm($id = null, $fields = null) { public function getEditForm($idOrRecord = null, $fields = null) {
if(!$idOrRecord) {
if(!$id) $id = $this->currentPageID(); $idOrRecord = $this->currentPageID();
$form = parent::getEditForm($id); }
$form = parent::getEditForm($idOrRecord);
// TODO Duplicate record fetching (see parent implementation) // TODO Duplicate record fetching (see parent implementation)
$record = $this->getRecord($id); $record = $this->getRecord($idOrRecord);
if($record && !$record->canView()) return Security::permissionFailure($this); if($record && !$record->canView()) return Security::permissionFailure($this);
if(!$fields) $fields = $form->Fields(); if(!$fields) $fields = $form->Fields();
$actions = $form->Actions(); $actions = $form->Actions();
if($record) { if($record) {
$id = $record->ID;
$deletedFromStage = $record->getIsDeletedFromStage(); $deletedFromStage = $record->getIsDeletedFromStage();
$deleteFromLive = !$record->getExistsOnLive(); $deleteFromLive = !$record->getExistsOnLive();
@ -733,7 +735,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->extend('updateEditForm', $form); $this->extend('updateEditForm', $form);
return $form; return $form;
} else if($id) { } else if($idOrRecord) {
$form = CMSForm::create( $this, "EditForm", new FieldList( $form = CMSForm::create( $this, "EditForm", new FieldList(
new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldList() new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldList()
)->setHTMLID('Form_EditForm'); )->setHTMLID('Form_EditForm');
@ -917,6 +919,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function setCurrentPageID($id) { public function setCurrentPageID($id) {
$id = (int)$id; $id = (int)$id;
$this->pageID = $id; $this->pageID = $id;
parent::setCurrentPageID($id);
} }
/** /**
@ -925,7 +928,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
* @return int * @return int
*/ */
public function currentPageID() { public function currentPageID() {
$id = $this->pageID; $id = $this->pageID ?: parent::currentPageID();
$this->extend('updateCurrentPageID', $id); $this->extend('updateCurrentPageID', $id);