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 Alert from CP Sidebar Delete Button/Action

Developer Preview

TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

I have a delete button on a sidebar item which posts to the URL I have specified and everything works, I’m able to delete the item and all, but I am unable to create an alert and defer it so it will show up when I redirect. There are no errors thrown, the alert just simply never appears. I’ve tried making it a banner, I’ve tried making it inline on a page that has a shared form. The alert simply doesn’t get created. Here’s my code.

$template = $this->constructTemplateService->getTemplateById(ee()->input->post('id'));

if (! $template) {
    // Code to handle errors
}

$this->constructTemplateService->deleteTemplateById($template->id);

// This is not showing up on the next page
ee('CP/Alert')->makeBanner('construct-template-deleted')
    ->asSuccess()
    ->canClose()
    ->withTitle(lang('templateDeleted'))
    ->addToBody(lang('templateDeletedBody'))
    ->defer();

ee()->functions->redirect(ee('CP/URL'->make('url/here');
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

And in your view, are you rendering all alerts identified by construct-template-deleted?

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

Note in this example, I’m making a banner, and I’ve tried different names and no name for the banner.

When I was trying to do inline, I was using 'shared-form', a custom name with getAllInlines() etc. It seems like the alert is simply not getting created or saved or something.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Ah yeah looks like we should be rendering all banners regardless of the name. I don’t see anything wrong in your code. The URL you’re redirecting to, could it be doing another redirect once it hits that URL? I’m wondering if that’s happening and the flashdata is getting purged out in the first request before it can display the CP again.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

No redirect on landing page.

       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

Does it display if you skip the redirect and use now()? And do you get a native success alert when saving an entry? I’m wondering if your flashdata cookie is corrupted, which could prevent all alerts from showing.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

I do get deferred alerts for other things (including saving a channel entry). I do get an alert if I use now and render my template without redirecting. However, specifically, when hitting my post endpoint from deleting in the sidebar, deferring a notification, and redirecting, I don’t get the deferred notification.

I’m uploading a video to Vimeo that shows what’s happening.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

Video: https://vimeo.com/230291152/002dea7da8

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Can you exit; or just not redirect after you call defer() and then inspect the contents of your flash cookie? Just to make sure what’s in there looks good.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

From the DeleteTemplateController after calling defer, no exp_flash key is set on $_COOKIE.

$this->eeAlertCollection->makeInline('shared-form')
    ->asSuccess()
    ->canClose()
    ->withTitle(lang('templateDeleted'))
    ->addToBody(strtr(lang('templateDeletedBody'), array(
        '{{templateName}}' => $template->construct_template_name
    )))
    ->defer();

var_dump($_COOKIE);
die;
array (size=6)
  'exp_last_visit' => string '1187817548' (length=10)
  'exp_last_activity' => string '1503177556' (length=10)
  'exp_csrf_token' => string '1ba175f74fd0e09523cfd2627cded138e2e335e7' (length=40)
  'exp_expiration' => string '1503181156' (length=10)
  'exp_remember' => string 'd75cb4704cb9b5258d595b6b561e97c5de56e859' (length=40)
  'exp_sessionid' => string 'adcc207df067328f3bedd66b74bc3cf4965c4d55' (length=40)

On a controller where it is working, here is the output from var_dump($_COOKIE); right after calling defer()

array (size=7)
  'exp_last_visit' => string '1187817548' (length=10)
  'exp_last_activity' => string '1503177556' (length=10)
  'exp_csrf_token' => string '1ba175f74fd0e09523cfd2627cded138e2e335e7' (length=40)
  'exp_expiration' => string '1503181156' (length=10)
  'exp_remember' => string 'd75cb4704cb9b5258d595b6b561e97c5de56e859' (length=40)
  'exp_flash' => string '{":new:alert:inline:shared-form":{"title":"Template Deleted","body":"<p>The Construct Template "Test Template" has been deleted successfully!</p>","severity":"success","can_close":true}}3d218845b9c0f0e1dce63e9340acbf8d1901cf254989cb53c797132c5384cd6595379e016b6ce681a089141d9b4d9d44' (length=282)
  'exp_sessionid' => string 'adcc207df067328f3bedd66b74bc3cf4965c4d55' (length=40)

It’s still entirely possible I may have a bug in my own code or doing something dumb, but I’m leaning pretty heavily toward this being a bug in EE code right now given this last debugging step and the fact that var_dumping $_COOKIE right after calling defer shows that exp_flash is not set.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

Dang it, hang on. Now I’m confused. Let me dig a little more.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

Okay, var_dumping cookie after calling defer()doesn’t show the cookie, but var_dumping $_COOKIE on the next request does show it’s there. But getAllInlines doesn’t get it. I’m so confused.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Can you try removing the double quotes from your message? The quotes here: "Test Template". I think they might be getting escaped at some point when generating/comparing against its hash and thus not making the hash comparison validate.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

Ah ha! That was it! Finally. I thought I was going to lose my mind.

Can we call this a bug with EE’s alert service/collection?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Yay! Yeah I guess it should be able to handle quotes.

       

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.