From cbf78cfc9453749f58d752991702e70d87618907 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 | 1 + src/VersionedGridFieldItemRequest.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lang/en.yml b/lang/en.yml index e22037bd..a63bdd4c 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -79,6 +79,7 @@ en: MoreOptions: 'More options' Published: 'Published {name} {link}' Unpublished: 'Unpublished {name} {title}' + PUBLISHEDTOASTMESSAGE: 'Published {name} {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..49fe988e 100644 --- a/src/VersionedGridFieldItemRequest.php +++ b/src/VersionedGridFieldItemRequest.php @@ -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->getRequest()->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 {name} {title}', + [ + 'name' => $record->i18n_singular_name(), + 'title' => Convert::raw2xml($record->Title) + ] + ); + + $controller = $this->getToplevelController(); + $controller->getRequest()->addHeader('X-Status', $message); + return $this->redirectAfterSave($isNewRecord); } @@ -215,6 +227,9 @@ public function doUnpublish($data, $form) ); $this->setFormMessage($form, $message); + $controller = $this->getToplevelController(); + $controller->getRequest()->addHeader('X-Status', $message); + // Redirect back to edit return $this->redirectAfterSave(false); }