mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
API-CHANGE: overriding DMS delete button (not quite working yet)
This commit is contained in:
parent
66a7a0a738
commit
44317bfbe6
@ -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;
|
||||
|
@ -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,
|
||||
|
53
code/cms/DMSGridFieldDetailForm.php
Normal file
53
code/cms/DMSGridFieldDetailForm.php
Normal 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
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user