Hey guys,
I’m trying to add draft publishing to EE similar to revisions. The main difference is drafts are not published to the live site.
I’ve used parts of the revision code as my “inspiration” but there’s one thing I cannot get right.
Currently when you click on a new revision the edit form loads, populates the $_POST variable with saved DB data and sets the form $which to preview.
I’m doing pretty much the same thing using another table and the publish_form_start hook. My issue is that the publish_form_start hook $which param is set to “edit”. So even though I load the $_POST variable up with the draft the it isn’t used.
I’ve tried using references to change the $which variable:
function publish_form_start( &$which, $submission_error, $entry_id, $hidden )
and although that works in the sessions_end hook I can’t get it to work here. I also hacked the core so that whatever publish_form_start returns will be assigned to the $which variable in Publish->new_entry_form(). This worked but Im guessing it would reek havoc on existing extensions.
Does anyone have any suggestions?
My solution..
Inside my publish_form_start hook method…
if($show_publish_form === TRUE && $IN->GBL('form_loaded') != 'y')
{
$_POST = $REGX->array_stripslashes(@unserialize($draft_data));
$_GET['form_loaded'] = "y";
$EE->new_entry_form('preview', "", $entry_id);
$EXT->end_script = TRUE;
}
Easy… :D
Leevi, is there any reason you can’t use the sessions_start
hook to overwrite the $_POST? That way you wouldn’t have to re-run the new_entry_form
method. The only concern I’d have is that duplicating new_entry_form
will call all extensions twice…
What about:
sessions_start()
{
if(/*loading draft*/)
{
$_POST = $REGX->array_stripslashes(@unserialize($draft_data));
$_POST['preview'] = 'preview';
}
}
I may be missing something, but I “think” that’d work…
Good point about the extensions being called twice… I’ll have to do some testing with that. Using sessions_start or sessions_end could be an option if I check that the page is the edit form to reduce overhead.
The client is doing some testing now so I’ll see what they come up with.
Leevi, is there any reason you can’t use the `sessions_start` hook to overwrite the $_POST? That way you wouldn’t have to re-run the `new_entry_form` method. The only concern I’d have is that duplicating `new_entry_form` will call all extensions twice… What about:I may be missing something, but I “think” that’d work…sessions_start() { if(/*loading draft*/) { $_POST = $REGX->array_stripslashes(@unserialize($draft_data)); $_POST['preview'] = 'preview'; } }
Hey Mark,
I ended up trying this but for seom reason EE kept redirecting me back to the CP homepage. My guess is it has something to do with XSS and the XID.
Still trying to find a solution
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.