From 52263e6a5f593b72d059d778cb916a6eb550418b Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 2 Sep 2012 16:57:50 +0200 Subject: [PATCH] BUG Gridfield fails when save changes filter criteria (fixes #7785) --- forms/gridfield/GridFieldDetailForm.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/forms/gridfield/GridFieldDetailForm.php b/forms/gridfield/GridFieldDetailForm.php index 63771be61a4..9addad26d4a 100644 --- a/forms/gridfield/GridFieldDetailForm.php +++ b/forms/gridfield/GridFieldDetailForm.php @@ -364,6 +364,7 @@ protected function getToplevelController() { function doSave($data, $form) { $new_record = $this->record->ID == 0; + $controller = Controller::curr(); try { $form->saveInto($this->record); @@ -371,7 +372,6 @@ function doSave($data, $form) { $this->gridField->getList()->add($this->record); } catch(ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); - $controller = Controller::curr(); $responseNegotiator = new PjaxResponseNegotiator(array( 'CurrentForm' => function() use(&$form) { return $form->forTemplate(); @@ -398,10 +398,16 @@ function doSave($data, $form) { if($new_record) { return Controller::curr()->redirect($this->Link()); - } else { + } elseif($this->gridField->getList()->byId($this->record->ID)) { // Return new view, as we can't do a "virtual redirect" via the CMS Ajax // to the same URL (it assumes that its content is already current, and doesn't reload) return $this->edit(Controller::curr()->getRequest()); + } else { + // Changes to the record properties might've excluded the record from + // a filtered list, so return back to the main view if it can't be found + $noActionURL = $controller->removeAction($data['url']); + $controller->getRequest()->addHeader('X-Pjax', 'Content'); + return $controller->redirect($noActionURL, 302); } }