Skip to content

Commit

Permalink
FIX ModelAdmin toast elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Nov 3, 2023
1 parent 69fcc2c commit 5416aff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ en:
Create: Create
Delete: Delete
DeletePermissionsFailure: 'No delete permissions'
Deleted: 'Deleted {type} {name}'
Deleted: 'Deleted {type} "{name}"'
Save: Save
Saved: 'Saved {name} {link}'
SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest:
Expand All @@ -111,6 +111,8 @@ en:
NEXT: 'Go to next record'
PREVIOUS: 'Go to previous record'
ViewPermissionsFailure: 'It seems you don''t have the necessary permissions to view "{ObjectTitle}"'
SAVETOASTMESSAGE: 'Saved {type} "{title}" successfully.'
SAVEDUP: 'Saved successfully.'
SilverStripe\Forms\GridField\GridFieldEditButton:
EDIT: Edit
SilverStripe\Forms\GridField\GridFieldFilterHeader:
Expand Down
21 changes: 19 additions & 2 deletions src/Forms/GridField/GridFieldDetailForm_ItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
Expand Down Expand Up @@ -543,6 +544,18 @@ public function doSave($data, $form)

$form->sessionMessage($message, 'good', ValidationResult::CAST_HTML);

$message = _t(
__CLASS__ . '.SAVETOASTMESSAGE',
'Saved {type} "{title}" successfully.',
[
'type' => $this->record->i18n_singular_name(),
'title' => Convert::raw2xml($this->record->Title)
]
);

$controller = $this->getToplevelController();
$controller->getRequest()->addHeader('X-Status', $message);

// Redirect after save
return $this->redirectAfterSave($isNewRecord);
}
Expand Down Expand Up @@ -706,7 +719,10 @@ protected function redirectAfterSave($isNewRecord)
} elseif ($this->gridField->getList()->byID($this->record->ID)) {
// Return new view, as we can't do a "virtual redirect" via the CMS Ajax
// to the same URL (it assumes that its content is already current, and doesn't reload)
return $this->edit($controller->getRequest());
$message = $controller->getRequest()->getHeader('X-Status') ?? rawurlencode(_t(__CLASS__ . '.SAVEDUP', 'Saved successfully') ?? '');
$response = new HTTPResponse($this->edit($controller->getRequest()));
$response->addHeader('X-Status', $message);
return $response;
} else {
// We might be able to redirect to open the record in a different view
if ($redirectDest = $this->component->getLostRecordRedirection($this->gridField, $controller->getRequest(), $this->record->ID)) {
Expand Down Expand Up @@ -782,7 +798,7 @@ public function doDelete($data, $form)

$message = _t(
'SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Deleted',
'Deleted {type} {name}',
'Deleted {type} "{name}"',
[
'type' => $this->record->i18n_singular_name(),
'name' => htmlspecialchars($title ?? '', ENT_QUOTES)
Expand All @@ -800,6 +816,7 @@ public function doDelete($data, $form)
//when an item is deleted, redirect to the parent controller
$controller = $this->getToplevelController();
$controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh
$controller->getRequest()->addHeader('X-Status', $message);

return $controller->redirect($this->getBackLink(), 302); //redirect back to admin section
}
Expand Down

0 comments on commit 5416aff

Please sign in to comment.