Created
October 11, 2012 05:51
-
-
Save frankmullenger/3870453 to your computer and use it in GitHub Desktop.
Delete message GridField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class GridFieldDetailForm_ItemRequest extends RequestHandler { | |
//... | |
public function doDelete($data, $form) { | |
try { | |
$toDelete = $this->record; | |
if (!$toDelete->canDelete()) { | |
throw new ValidationException( | |
_t('GridFieldDetailForm.DeletePermissionsFailure',"No delete permissions"),0); | |
} | |
$toDelete->delete(); | |
} catch(ValidationException $e) { | |
$form->sessionMessage($e->getResult()->message(), 'bad'); | |
return Controller::curr()->redirectBack(); | |
} | |
$toplevelController = $this->getToplevelController(); | |
if($toplevelController && $toplevelController instanceof LeftAndMain) { | |
$backForm = $toplevelController->getEditForm(); | |
$message = sprintf( | |
_t('GridFieldDetailForm.Deleted', 'Deleted %s %s'), | |
$this->record->singular_name(), | |
'' | |
); | |
$backForm->sessionMessage($message, 'good'); | |
} | |
//when an item is deleted, redirect to the revelant admin section without the action parameter | |
$controller = Controller::curr(); | |
$controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh | |
return $controller->redirect($this->getBacklink(), 302); //redirect back to admin section | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment