Skip to content

Commit

Permalink
Merge pull request #424 from creative-commoners/pulls/1.13/toast-msg-…
Browse files Browse the repository at this point in the history
…gridfield

FIX ModelAdmin toast elements
  • Loading branch information
GuySartorelli authored Nov 12, 2023
2 parents 59299b6 + c52c166 commit 62f78a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 18 additions & 3 deletions src/VersionedGridFieldItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -207,14 +219,17 @@ public function doUnpublish($data, $form)

$message = _t(
__CLASS__ . '.Unpublished',
'Unpublished {name} {title}',
'Unpublished {name} "{title}"',
[
'name' => $record->i18n_singular_name(),
'title' => Convert::raw2xml($title)
]
);
$this->setFormMessage($form, $message);

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

// Redirect back to edit
return $this->redirectAfterSave(false);
}
Expand Down

0 comments on commit 62f78a9

Please sign in to comment.