mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
commit
af3412a4c2
@ -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")) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user