Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: issue with native fields not saving when using custom redirect in the after_channel_entry_save hook

Status Resolved
Add-on / Version Publisher Lite 3.9.1
Severity
EE Version 7.2.10

Mark Mikloska

Jun 14, 2023

Hi Brian

Me again.
I have another interesting one.

Using publisher lite, my client would like to change the way it works post save.
At the moment, if you’re viewing a draft and saving as draft, it will redirect you to published view post save.
What we basically want is to redirect to whatever you select in the “save as” dropdown (eg. draft -> draft version, published -> published version)
So if I am editing a published version and save it draft, I wanna end up on the “view” draft.

I thought it would be simple, by just adding “after_channel_entry_save” hook to my addon but it seems like it’s not as straight forward as I thought.

Basically it almost works as expected 😊
The issue is when I publish anything, it shows correctly in CP and all is saved correctly in Publisher, Bloqs… fields.
But the EE native fields don’t save, they still show the old values.

This is the script I run inside the after_channel_entry_save hook.

public function after_channel_entry_save($channelEntry, $entryData = [])
  {
if ($lastSavedEntry = FlashBag::get('lastSavedEntry')) {
$url = sprintf('/welcome/index.php?/cp/publish/edit/entry/%d', $lastSavedEntry['entryId']);

if ($lastSavedEntry['status'] == 'draft') {
$url .= '&publisher_status=draft&lang_id=1';
FlashBag::set('lastSavedEntry', $lastSavedEntry);
ee()->extensions->end_script = TRUE;
ee()->functions->redirect($url);
}
}}

Any help would be much appreciated.

#1

BoldMinded (Brian)

If you perform a redirect in any of the entry event hooks, it’ll likely mess up any other add-ons also using that event hook b/c it will interrupt the call chain and those add-on hooks won’t trigger.

There is a “Save As” option in Publisher’s settings that you can set it to “Same” - did you see that?

I’ve been thinking about this a bit since the email and I don’t think I want to add any additional code to alter the redirection or save process. What you’re seeing has been this way for years and this is the first time I’ve received such a request.

#2

Mark Mikloska

Thanks Brian

I totally understand, not my idea to change the way the redirects work. Also I made sure I run the hook as a last one, by increasing the priority to above all other add-ons, so they all run before the redirect.

It’s just weird that Bloqs etc… all save fine, but none of the native fields do. I’d expect them to be saved by the time the hook gets triggered?

cheers, Mark

#3

BoldMinded (Brian)

Have you tried re-creating the issue in a new EE environment with just Publisher installed? No other add-ons or customizations?

Login to reply