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

Assign new value to $which in publish_form_start hook

Development and Programming

Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

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?

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

My solution..

Inside my publish_form_start hook method…

  1. Check to see if the draft is being loaded
  2. Fill the $_POST variable with data
  3. Flag that the publish form has been called by the method (stops infinite loops)
  4. Load a new entry form with the preview flag
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

       
gridonic's avatar
gridonic
231 posts
16 years ago
gridonic's avatar gridonic

Nice. But did you find out whe the

which

variable couldn’t be set to “preview” in the first place?

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

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…

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

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 Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

I could also make the priority 1 so that my extension runs before all others. This would reduce the chance of duplicate extensions.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham
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…

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

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

Mark,

I ended up using a core hack like you implemented in your Multi-Relationship Module to make $which a referenced variable in my extension.

Cheers Leevi

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

Glad you figured it out and although core hacks make my skin crawl, your approach was probably the cleanest.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

Yeah I thoughts so as well but then it stopped working and I couldn’t figure out why!

       

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.