Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Fix issue with gridfield actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tractorcow committed Nov 21, 2019
1 parent 4a78844 commit 68a32aa
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/Extension/FluentGridFieldExtension.php
Expand Up @@ -2,6 +2,7 @@

namespace TractorCow\Fluent\Extension;

use SilverStripe\Control\Controller;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
Expand Down Expand Up @@ -40,17 +41,43 @@ public function updateFormActions(FieldList $actions)
}

/**
* @param Form $form
* @param Form $form
* @param string $message
* @return mixed
*/
public function actionComplete($form, $message)
{
$form->sessionMessage($message, 'good', ValidationResult::CAST_HTML);

$link = $form->getController()->Link();
// Copied fcrom GridFieldDetailForm_ItemRequest::redirectAfterSave
$controller = $this->getToplevelController();
$gridField = $this->owner->getGridField();
$record = $this->owner->getRecord();
$request = $controller->getRequest();

// 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)
if ($gridField->getList()->byID($record->ID)) {
return $this->owner->edit($request);
}

// 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
$url = $request->getURL();
$noActionURL = $controller->removeAction($url);
$request->addHeader('X-Pjax', 'Content');
return $controller->redirect($noActionURL, 302);
}

// TODO: This redirect doesn't work
return $this->owner->getController()->redirect($link);
/**
* @return Controller
*/
private function getToplevelController()
{
$next = $this->owner;
while ($next && $next instanceof GridFieldDetailForm_ItemRequest) {
$next = $next->getController();
}
return $next;
}
}

0 comments on commit 68a32aa

Please sign in to comment.