fix to grid field loading wrong current page id when using multiple tabs

This commit is contained in:
John Milmine 2016-04-19 21:38:32 +12:00
parent 936dcb691b
commit 66ed97e08e
2 changed files with 11 additions and 0 deletions

View File

@ -1481,6 +1481,9 @@ class LeftAndMain extends Controller implements PermissionProvider {
public function currentPageID() {
if($this->getRequest()->requestVar('ID') && is_numeric($this->getRequest()->requestVar('ID'))) {
return $this->getRequest()->requestVar('ID');
} elseif ($this->getRequest()->requestVar('CMSMainCurrentPageID') && is_numeric($this->getRequest()->requestVar('CMSMainCurrentPageID'))) {
// see GridFieldDetailForm::ItemEditForm
return $this->getRequest()->requestVar('CMSMainCurrentPageID');
} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID'];
} elseif(Session::get($this->sessionNamespace() . ".currentPage")) {

View File

@ -405,6 +405,14 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
}
}
// this pushes the current page ID in as a hidden field
// this means the request will have the current page ID in it
// rather than relying on session which can have been rewritten
// by the user having another tab open
// see LeftAndMain::currentPageID
if($this->controller->hasMethod('currentPageID') && $this->controller->currentPageID()) {
$fields->push(new HiddenField('CMSMainCurrentPageID', null, $this->controller->currentPageID()));
}
// Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead.
// Thanks to this however, we are able to nest GridFields, and also access the initial Controller by
// dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController