Skip to content

Instantly share code, notes, and snippets.

@frankmullenger
Created October 11, 2012 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankmullenger/3870453 to your computer and use it in GitHub Desktop.
Save frankmullenger/3870453 to your computer and use it in GitHub Desktop.
Delete message GridField
<?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