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 1, 2023
1 parent 59299b6 commit cbf78cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion src/VersionedGridFieldItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -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);
}
Expand Down

0 comments on commit cbf78cf

Please sign in to comment.