adding page id into cmsmain

This commit is contained in:
Tim Kung 2017-04-07 14:41:15 +12:00
parent af1002194d
commit 487235f991

View File

@ -15,6 +15,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
private static $url_rule = '/$Action/$ID/$OtherID'; private static $url_rule = '/$Action/$ID/$OtherID';
private static $url_handlers = array(
'EditForm/$ID' => 'EditForm',
);
// Maintain a lower priority than other administration sections // Maintain a lower priority than other administration sections
// so that Director does not think they are actions of CMSMain // so that Director does not think they are actions of CMSMain
private static $url_priority = 39; private static $url_priority = 39;
@ -66,6 +70,13 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
*/ */
private static $enabled_legacy_actions = array(); private static $enabled_legacy_actions = array();
/**
* The page id for this request
*
* @var int|null
*/
protected $pageID = null;
public function init() { public function init() {
// set reading lang // set reading lang
if(SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) { if(SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
@ -592,6 +603,29 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} }
} }
/**
* Ensuring we set the current page id from the $ID url parameter.
*
* @param SS_HTTPRequest $request
*
* @return Form
*/
public function EditForm($request = null) {
// set page ID from request
if ($request) {
// validate id is present
$id = $request->param('ID');
if (!isset($id)) {
return $this->httpError(400);
}
$this->setCurrentPageID($id);
}
return $this->getEditForm();
}
/** /**
* @param int $id * @param int $id
* @param FieldList $fields * @param FieldList $fields
@ -690,6 +724,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$form->setFields($readonlyFields); $form->setFields($readonlyFields);
} }
// update form action to include $pageID
$form->setFormAction(Controller::join_links($form->FormAction(), $id));
$this->extend('updateEditForm', $form); $this->extend('updateEditForm', $form);
return $form; return $form;
} else if($id) { } else if($id) {
@ -866,8 +903,25 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $listview; return $listview;
} }
/**
* Set the page id into $pageID rather than into {@link Session}.
*
* @param string|int $id
*
* @return void
*/
public function setCurrentPageID($id) {
$id = (int)$id;
$this->pageID = $id;
}
/**
* Get the page id from this request
*
* @return int
*/
public function currentPageID() { public function currentPageID() {
$id = parent::currentPageID(); $id = $this->pageID;
$this->extend('updateCurrentPageID', $id); $this->extend('updateCurrentPageID', $id);