We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

CP Alerts set at runtime override all deferred alerts?

Developer Preview

Derek Hogue's avatar
Derek Hogue
316 posts
9 years ago
Derek Hogue's avatar Derek Hogue

I have a situation where I want to display an alert to the user when they load my add-on’s settings screen if certain conditions are met. To do this, I’m using a now() alert call. e.g.

if($vars['token_status'] == 'error')
{
    ee('CP/Alert')->makeInline('shared-form')
        ->asWarning()
        ->withTitle(lang('da_existing_token_error_heading'))
        ->addToBody(lang('da_existing_token_error'))
        ->cannotClose()
        ->now();
}

But I’m also redirecting back to this same screen after I save some settings, and in that save method, I’m deferring a success message:

ee('CP/Alert')->makeInline('shared-form')
        ->asSuccess()
        ->withTitle(lang('da_token_saved_heading'))
        ->addToBody(lang('da_token_saved_desc'))
        ->defer();

The issue is that sometimes I’ll need to display both alerts on the same screen, each generated by a different method (one at runtime, one before a redirect) - but it appears as though the existence of any now() alerts removes any previous defer() alerts - is that correct? And if so, any way around this?

       
Seth Barber's avatar
Seth Barber
172 posts
9 years ago
Seth Barber's avatar Seth Barber

Hi Derek,

It looks like you are using the shared form as your view. By default that will load the alert saved as shared-form, but it can also take a extra_alerts parameter, which should be an array naming any and all other alerts you’d like to display on the page. When you do this, you’ll need to match the string you pass to makeInline().

       
Derek Hogue's avatar
Derek Hogue
316 posts
9 years ago
Derek Hogue's avatar Derek Hogue

Thanks Seth, that led me down the right path.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.