You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to trigger a toast notification using the X-Status header within an extension file for File.php within this module. I can see my HTTP response triggering in the dev tools network tab correctly, with the X-Status header being applied, but it's not triggering the toast notification.
How to reproduce
I have a few functions i'd like to trigger this toast notification, but for simplicity I am showing one example. I am initialising an AWS S3 Client in an onBeforeWrite function, and in the function I am checking if the correct ENV vars are set. If they're not I am wanting to throw an error for configuration issues utilising a toast notification.
When publishing a file and not having those credentials set, I can see it erroring as expected in the network tab with the messaging and the X-Status header adding to the response, but nothing visually happens in terms of toast notifications in the CMS.
I got the example for the HTTPResponse_Exception from the LeftAndMain.php within the silverstripe-admin module:
The JS code that uses the X-Status code is very old and relies on the XHR request being triggered specifically by request that was triggered from jQuery.ajax(), and not some other mechanism like the newer fetch(). I wasn't even personally aware you could trigger toasts via a status header until reading this issue.
There isn't really a reliable way to trigger toasts from PHP. We trigger them manually using JS within react components use a redux action, though it's also possible to trigger them via a jquery call. That's probably not too helpful for what you're doing.
Since this issue isn't a bug I'll close this issue
Morning @emteknetnz, thanks for looking into this initially.
As @GuySartorelli mentioned, it says in the docs that it's a way to trigger toast notifications X-Status: Extended status information, used for an information popover (aka "toast" message).. If that's not the case anymore it should probably be removed from the docs.
I can see the X-Status header being used in a fair few Silverstripe modules so I'd assume it still has some use.
Module version(s) affected
2.2
Description
I am trying to trigger a toast notification using the
X-Status
header within an extension file forFile.php
within this module. I can see my HTTP response triggering in the dev tools network tab correctly, with theX-Status
header being applied, but it's not triggering the toast notification.How to reproduce
I have a few functions i'd like to trigger this toast notification, but for simplicity I am showing one example. I am initialising an AWS S3 Client in an
onBeforeWrite
function, and in the function I am checking if the correct ENV vars are set. If they're not I am wanting to throw an error for configuration issues utilising a toast notification.My
config.yml
:This is the initialise function - the
if
block being my error I wish to throw:The
onBeforeWrite
function:When publishing a file and not having those credentials set, I can see it erroring as expected in the network tab with the messaging and the
X-Status
header adding to the response, but nothing visually happens in terms of toast notifications in the CMS.I got the example for the
HTTPResponse_Exception
from theLeftAndMain.php
within thesilverstripe-admin
module:Any thoughts on why mine might not be triggering? Is it a bug, or have I completely misunderstood the use of the
X-Status
header?Thanks in advance :D
Possible Solution
No response
Additional Context
No response
Validations
silverstripe/installer
(with any code examples you've provided)The text was updated successfully, but these errors were encountered: