From 44317bfbe680c59ff036a47df75cbf2ce38a0167 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Wed, 1 Aug 2012 18:37:53 +1200 Subject: [PATCH] API-CHANGE: overriding DMS delete button (not quite working yet) --- code/DMSDocument.php | 2 ++ code/DMSSiteTreeExtension.php | 4 +++ code/cms/DMSGridFieldDetailForm.php | 53 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 code/cms/DMSGridFieldDetailForm.php diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 183721c..3adf294 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -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; diff --git a/code/DMSSiteTreeExtension.php b/code/DMSSiteTreeExtension.php index b6fcfbc..0b12f4e 100644 --- a/code/DMSSiteTreeExtension.php +++ b/code/DMSSiteTreeExtension.php @@ -25,6 +25,10 @@ class DMSSiteTreeExtension extends DataExtension { $gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields) ->setFieldCasting(array('LastChanged'=>"Date->Ago")) ->setFieldFormatting(array('FilenameWithoutID'=>'$FilenameWithoutID')); + + //override delete functionality with this class + $gridFieldConfig->getComponentByType('GridFieldDetailForm')->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest'); + $gridField = GridField::create( 'Documents', false, diff --git a/code/cms/DMSGridFieldDetailForm.php b/code/cms/DMSGridFieldDetailForm.php new file mode 100644 index 0000000..c59cac0 --- /dev/null +++ b/code/cms/DMSGridFieldDetailForm.php @@ -0,0 +1,53 @@ +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(), + '"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"' + ); + + $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 + } + +} \ No newline at end of file