XF 2.2 Change thread titles

I want to change thread titles in my overridden method, I have tried changing _POST and _REQUEST, I can see the global variables were changed successfully, but they are not used in the posted thread. How can I change it? Thanks!

PHP:
public function actionPostThread(ParameterBag $params)
{
       $_REQUEST['title'] = $title;
       $_POST['title'] = $title;
}
 
Use the $params to get the incoming title instead of using $_request or $_post.

And once you are done with that, then use the entity to update it.

You can also check the tutorial for this.
 
I do something like this in my overridden setupThreadCreate method to change my title to one combining a couple of custom fields (I've removed the title field from the template in the relevant forums)

PHP:
    protected function setupThreadCreate(\XF\Entity\Forum $forum)
    {
        $creator = parent::setupThreadCreate($forum);
        
        $original_message = $creator->getPost()->message;
        $custom_fields = $this->filter('custom_fields', 'array');
        
        $title = "$custom_fields[site] - $custom_fields[prize]";
        
        $creator->setContent($title, $original_message);
        
        return $creator;
    }

It looks like $title = $this->filter('title', 'str'); would give you the original title in that method too.

Hope that helps.
 
Back
Top Bottom