API-CHANGE: overriding DMS delete button (not quite working yet)

This commit is contained in:
Julian Seidenberg 2012-08-01 18:37:53 +12:00
parent 66a7a0a738
commit 44317bfbe6
3 changed files with 59 additions and 0 deletions

View File

@ -470,6 +470,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$fields->add($UploadField);
$fields->add($pagesGrid);
$fields->add(FormAction::create('dod', _t('GridFieldDetailForm.Delete', 'Delete'))
->addExtraClass('ss-ui-action-destructive')); //delete button
return $fields;

View File

@ -25,6 +25,10 @@ class DMSSiteTreeExtension extends DataExtension {
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields)
->setFieldCasting(array('LastChanged'=>"Date->Ago"))
->setFieldFormatting(array('FilenameWithoutID'=>'<a target=\'_blank\' class=\'file-url\' href=\'$DownloadLink\'>$FilenameWithoutID</a>'));
//override delete functionality with this class
$gridFieldConfig->getComponentByType('GridFieldDetailForm')->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest');
$gridField = GridField::create(
'Documents',
false,

View File

@ -0,0 +1,53 @@
<?php
/**
* Custom ItemRequest class the provides custom delete behaviour for the CMSFields of DMSDocument
*/
class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest {
function ItemEditForm() {
$form = parent::ItemEditForm();
//could try and remove the delete button here (or just hide it in css)
return $form;
}
/**
* Overriding delete functionality with our own
* @param $data
* @param $form
* @return mixed
* @throws ValidationException
*/
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();
}
$message = sprintf(
_t('GridFieldDetailForm.Deleted', 'Deleted %s %s'),
$this->record->singular_name(),
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
);
$form->sessionMessage($message, 'good');
//when an item is deleted, redirect to the revelant admin section without the action parameter
$controller = Controller::curr();
$noActionURL = $controller->removeAction($data['url']);
$controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh
return $controller->redirect($noActionURL, 302); //redirect back to admin section
}
}