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');
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.
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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.