Merge pull request #5340 from dnadesign/fixToGridFieldLoadingWrongCurrentPage

fix to grid field loading wrong current page id when using multiple tabs
This commit is contained in:
Daniel Hensby 2016-08-02 12:44:11 +01:00 committed by GitHub
commit af3412a4c2
2 changed files with 11 additions and 0 deletions

View File

@ -1484,6 +1484,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