Permalink
Browse files

FIX 7927 Redirect to the parent controller after deleting an item in …

…a gridfield (edit form)
  • Loading branch information...
1 parent 5186bad commit 574c53d5ba522f43650d9cd4de2d51dd57b53a32 @patbolo patbolo committed with chillu Oct 7, 2012
Showing with 36 additions and 19 deletions.
  1. +36 −19 forms/gridfield/GridFieldDetailForm.php
@@ -326,7 +326,7 @@ public function ItemEditForm() {
$this->component->getValidator()
);
if($this->record->ID !== 0) {
- $form->loadDataFrom($this->record);
+ $form->loadDataFrom($this->record);
}
// TODO Coupling with CMS
@@ -341,16 +341,9 @@ public function ItemEditForm() {
if($form->Fields()->hasTabset()) {
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->addExtraClass('ss-tabset cms-tabset');
- }
-
- if($toplevelController->hasMethod('Backlink')) {
- $form->Backlink = $toplevelController->Backlink();
- } elseif($this->popupController->hasMethod('Breadcrumbs')) {
- $parents = $this->popupController->Breadcrumbs(false)->items;
- $form->Backlink = array_pop($parents)->Link;
- } else {
- $form->Backlink = $toplevelController->Link();
}
+
+ $form->Backlink = $this->getBackLink();
}
$cb = $this->component->getItemEditFormCallback();
@@ -373,6 +366,25 @@ protected function getToplevelController() {
}
return $c;
}
+
+ protected function getBackLink(){
+ // TODO Coupling with CMS
+ $backlink = '';
+ $toplevelController = $this->getToplevelController();
+ if($toplevelController && $toplevelController instanceof LeftAndMain) {
+ if($toplevelController->hasMethod('Backlink')) {
+ $backlink = $toplevelController->Backlink();
+ } elseif($this->popupController->hasMethod('Breadcrumbs')) {
+ $parents = $this->popupController->Breadcrumbs(false)->items;
+ $backlink = array_pop($parents)->Link;
+ } else {
+ $backlink = $toplevelController->Link();
+ }
+ }
+ return $backlink;
+ }
+
+
public function doSave($data, $form) {
$new_record = $this->record->ID == 0;
@@ -424,14 +436,14 @@ public function doSave($data, $form) {
}
public function doDelete($data, $form) {
+ $title = $this->record->Title;
try {
- $toDelete = $this->record;
- if (!$toDelete->canDelete()) {
+ if (!$this->record->canDelete()) {
throw new ValidationException(
_t('GridFieldDetailForm.DeletePermissionsFailure',"No delete permissions"),0);
}
- $toDelete->delete();
+ $this->record->delete();
} catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return Controller::curr()->redirectBack();
@@ -440,17 +452,22 @@ public function doDelete($data, $form) {
$message = sprintf(
_t('GridFieldDetailForm.Deleted', 'Deleted %s %s'),
$this->record->singular_name(),
- '<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
+ htmlspecialchars($title, ENT_QUOTES)
);
+
+ $toplevelController = $this->getToplevelController();
+ if($toplevelController && $toplevelController instanceof LeftAndMain) {
+ $backForm = $toplevelController->getEditForm();
+ $backForm->sessionMessage($message, 'good');
+ } else {
+ $form->sessionMessage($message, 'good');
+ }
- $form->sessionMessage($message, 'good');
-
- //when an item is deleted, redirect to the revelant admin section without the action parameter
+ //when an item is deleted, redirect to the parent controller
$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
+ return $controller->redirect($this->getBacklink(), 302); //redirect back to admin section
}
/**

0 comments on commit 574c53d

Please sign in to comment.