From c52c1661cb9fc3cb81345373a18fff75313f009b Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Thu, 2 Nov 2023 11:05:09 +1300 Subject: [PATCH] FIX ModelAdmin toast elements --- lang/en.yml | 5 +++-- src/VersionedGridFieldItemRequest.php | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lang/en.yml b/lang/en.yml index e22037bd..18bd8858 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -66,7 +66,7 @@ en: db_Version: Version has_many_Versions: Versions SilverStripe\Versioned\VersionedGridFieldItemRequest: - Archived: 'Archived {name} {title}' + Archived: 'Archived {name} "{title}"' BUTTONAPPLYCHANGES: 'Apply changes' BUTTONARCHIVEDESC: 'Unpublish and send to archive' BUTTONPUBLISHED: Published @@ -78,7 +78,8 @@ en: MODIFIED: Modified MoreOptions: 'More options' Published: 'Published {name} {link}' - Unpublished: 'Unpublished {name} {title}' + Unpublished: 'Unpublished {name} "{title}"' + PUBLISHEDTOASTMESSAGE: 'Published {type} "{title}"' SilverStripe\Versioned\VersionedGridFieldState\VersionedGridFieldState: ADDEDTODRAFTHELP: 'Item has not been published yet' ADDEDTODRAFTSHORT: Draft diff --git a/src/VersionedGridFieldItemRequest.php b/src/VersionedGridFieldItemRequest.php index b95f3893..1b11a56b 100644 --- a/src/VersionedGridFieldItemRequest.php +++ b/src/VersionedGridFieldItemRequest.php @@ -133,7 +133,7 @@ public function doArchive($data, $form) $message = _t( __CLASS__ . '.Archived', - 'Archived {name} {title}', + 'Archived {name} "{title}"', [ 'name' => $record->i18n_singular_name(), 'title' => Convert::raw2xml($title) @@ -144,7 +144,7 @@ public function doArchive($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->getResponse()->addHeader('X-Status', $message); return $controller->redirect($this->getBackLink(), 302); //redirect back to admin section } @@ -183,6 +183,18 @@ public function doPublish($data, $form) ); $this->setFormMessage($form, $message); + $message = _t( + __CLASS__ . '.PUBLISHEDTOASTMESSAGE', + 'Published {type} "{title}"', + [ + 'type' => $record->i18n_singular_name(), + 'title' => Convert::raw2xml($record->Title) + ] + ); + + $controller = $this->getToplevelController(); + $controller->getResponse()->addHeader('X-Status', $message); + return $this->redirectAfterSave($isNewRecord); } @@ -207,7 +219,7 @@ public function doUnpublish($data, $form) $message = _t( __CLASS__ . '.Unpublished', - 'Unpublished {name} {title}', + 'Unpublished {name} "{title}"', [ 'name' => $record->i18n_singular_name(), 'title' => Convert::raw2xml($title) @@ -215,6 +227,9 @@ public function doUnpublish($data, $form) ); $this->setFormMessage($form, $message); + $controller = $this->getToplevelController(); + $controller->getResponse()->addHeader('X-Status', $message); + // Redirect back to edit return $this->redirectAfterSave(false); }