mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENH Restore gridfield state from get vars
This commit is contained in:
parent
6c5448b70f
commit
a8652f7cbb
@ -4,10 +4,12 @@ namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HasRequestHandler;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\HTTPResponse_Exception;
|
||||
use SilverStripe\Control\NullHTTPRequest;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
@ -45,6 +47,8 @@ use SilverStripe\View\HTML;
|
||||
*/
|
||||
class GridField extends FormField
|
||||
{
|
||||
use GridFieldStateAware;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@ -435,6 +439,8 @@ class GridField extends FormField
|
||||
{
|
||||
$this->state = new GridState($this);
|
||||
|
||||
$this->addStateFromRequest();
|
||||
|
||||
$data = $this->state->getData();
|
||||
|
||||
foreach ($this->getComponents() as $item) {
|
||||
@ -444,6 +450,32 @@ class GridField extends FormField
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds state for this gridfield from the request variables.
|
||||
*
|
||||
* If there is state already set on this GridField, that takes precedent
|
||||
* over state from the request.
|
||||
*/
|
||||
private function addStateFromRequest(): void
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
if (($request instanceof NullHTTPRequest) && Controller::has_curr()) {
|
||||
$request = Controller::curr()->getRequest();
|
||||
}
|
||||
if ($request->params()['Action']) {
|
||||
return;
|
||||
}
|
||||
$stateStr = $this->getStateManager()->getStateFromRequest($this, $request);
|
||||
if ($stateStr) {
|
||||
$oldState = $this->getState(false);
|
||||
// Create a dummy state so that we can merge the current state with the request state.
|
||||
$newState = new GridState($this, $stateStr);
|
||||
// Put the current state on top of the request state.
|
||||
$newState->setValue($oldState->Value());
|
||||
$this->state = $newState;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the whole gridfield rendered with all the attached components.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user