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 59299b6 commit e041bba
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 {name} "{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->getRequest()->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 {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);
}

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->getRequest()->addHeader('X-Status', $message);

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

0 comments on commit e041bba

Please sign in to comment.