XF 2.0 Get variables from parent class, on a $redirect?

Honestly @Snog, I COMPLETELY agree with you. Which is why I said previously in this thread that it seems "wrong".

While yes, doing the redirect shouldn't have any conflicts with the normal expected functionality of the subroutine, it would have a problem with two addons use redirects, and both conditionals would be positive.... only one of them could execute.

However, this problem would exist no matter where the redirect existed. You can only do one redirect. So this is the best case, in putting the redirect right at the end of the execution chain.
 
Honestly @Snog, I COMPLETELY agree with you. Which is why I said previously in this thread that it seems "wrong".

While yes, doing the redirect shouldn't have any conflicts with the normal expected functionality of the subroutine, it would have a problem with two addons use redirects, and both conditionals would be positive.... only one of them could execute.

However, this problem would exist no matter where the redirect existed. You can only do one redirect. So this is the best case, in putting the redirect right at the end of the execution chain.
Thank you! You at least seem to understanding what I'm saying.

But, putting a redirect in finalizeThreadCreate forces everyone to do the same thing. Under normal circumstances the redirect is done after finalizeThreadCreate is done running (see any stock XF thread creation routine such as Forum.php), not in the finalizeThreadCreate function itself.

And believe me this was never meant to be a comment about your add-on. I fully understand why it's there and I can work around it. It was just a general comment about using the redirect there.

And the bigger point was that because there's not normally a redirect in that function, other developers should be aware that there's a clear possiblity that it's there so they can either create their own finalizeThreadCreate function or make other adjustments to account for it. Personally I never expected a redirect there and didn't do anything originally. It wasn't until a client had problems and I was able to track it down to the finalizeThreadCreate function having a redirect in it. So I would think other developers might run across the same situation at some point.
 
I'm looking for a solution to get the thread_id in actionPostThread on save.
I save my own entity stuff in this action and i need the thread_id from new created thread to save it with my own stuff.
I figured something out, that i would share.

PHP:
//extended XF\Pub\Controller\Forum

protected $threadID;

public function actionPostThread(ParameterBag $params)
{
    $reply = parent::actionPostThread($params);
    if ($this->isPost())
    {
        $stuffFromPost = $this->filter('stuffFromPost ', 'array');
        if($stuffFromPost ){
              $ownEntity= \XF::em()->create('OWN\ENTITY:STUFF');

              //access to the variable set in finalizeThreadCreate
              $thread_id = $this->threadID

              $ownEntity->set('someStuff', $stuffFromPost);
              $ownEntity->set('threadID', $thread_id );
              $ownEntity->save();

        }
    }
   
    return $reply;
}

protected function finalizeThreadCreate(\XF\Service\Thread\Creator $creator)
{
    parent::finalizeThreadCreate($creator);

    $thread = $creator->getThread();
    $this->threadID = $thread->thread_id;
}

It works but is it the right way to do this ?
I hope someone can say something to that solution.
 
Top Bottom