Merge pull request #11037 from creative-commoners/pulls/4.13/toast-msg-gridfield

FIX ModelAdmin toast elements
This commit is contained in:
Guy Sartorelli 2023-11-13 09:43:38 +13:00 committed by GitHub
commit 4c76ec6102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -103,7 +103,7 @@ en:
Create: Create Create: Create
Delete: Delete Delete: Delete
DeletePermissionsFailure: 'No delete permissions' DeletePermissionsFailure: 'No delete permissions'
Deleted: 'Deleted {type} {name}' Deleted: 'Deleted {type} "{name}"'
Save: Save Save: Save
Saved: 'Saved {name} {link}' Saved: 'Saved {name} {link}'
SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest: SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest:
@ -112,6 +112,8 @@ en:
NEXT: 'Go to next record' NEXT: 'Go to next record'
PREVIOUS: 'Go to previous record' PREVIOUS: 'Go to previous record'
ViewPermissionsFailure: 'It seems you don''t have the necessary permissions to view "{ObjectTitle}"' 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: SilverStripe\Forms\GridField\GridFieldEditButton:
EDIT: Edit EDIT: Edit
SilverStripe\Forms\GridField\GridFieldFilterHeader: SilverStripe\Forms\GridField\GridFieldFilterHeader:

View File

@ -8,6 +8,7 @@ use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\RequestHandler; use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\CompositeField; use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
@ -543,6 +544,18 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
$form->sessionMessage($message, 'good', ValidationResult::CAST_HTML); $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->getResponse()->addHeader('X-Status', $message);
// Redirect after save // Redirect after save
return $this->redirectAfterSave($isNewRecord); return $this->redirectAfterSave($isNewRecord);
} }
@ -706,6 +719,8 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
} elseif ($this->gridField->getList()->byID($this->record->ID)) { } elseif ($this->gridField->getList()->byID($this->record->ID)) {
// Return new view, as we can't do a "virtual redirect" via the CMS Ajax // 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) // to the same URL (it assumes that its content is already current, and doesn't reload)
$message = $controller->getResponse()->getHeader('X-Status') ?? rawurlencode(_t(__CLASS__ . '.SAVEDUP', 'Saved successfully') ?? '');
$controller->getResponse()->addHeader('X-Status', $message);
return $this->edit($controller->getRequest()); return $this->edit($controller->getRequest());
} else { } else {
// We might be able to redirect to open the record in a different view // We might be able to redirect to open the record in a different view
@ -782,7 +797,7 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
$message = _t( $message = _t(
'SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Deleted', 'SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Deleted',
'Deleted {type} {name}', 'Deleted {type} "{name}"',
[ [
'type' => $this->record->i18n_singular_name(), 'type' => $this->record->i18n_singular_name(),
'name' => htmlspecialchars($title ?? '', ENT_QUOTES) 'name' => htmlspecialchars($title ?? '', ENT_QUOTES)
@ -800,6 +815,7 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
//when an item is deleted, redirect to the parent controller //when an item is deleted, redirect to the parent controller
$controller = $this->getToplevelController(); $controller = $this->getToplevelController();
$controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh $controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh
$controller->getResponse()->addHeader('X-Status', $message);
return $controller->redirect($this->getBackLink(), 302); //redirect back to admin section return $controller->redirect($this->getBackLink(), 302); //redirect back to admin section
} }