XF 2.3 Thread Types

Lee

Well-known member
I’m looking to create a new thread type.

Can somebody help me in understanding the steps required to implement a new thread type?

I have inserted it as a thread type in the database

I have also created a thread type handler for my thread type.

How do I get it to be recognised by XenForo?
 
Are you talking about having it appear in the post thread options and in the node edit options?
To get it like this, you need to do a few things.

First off make sure your thread type is being registered correctly.
PHP:
    public function installStep1(): void
    {
        $this->insertThreadType('test', 'Vendor\Addon:Test', 'Vendor/Addon');
    }
What this does is inserts that data into the database and rebuilds the rebuildThreadTypeCache

Before carrying on check the database table xf_thread_type that your new type exists, just to make sure.

Next you'll want to add your thread type handler
PHP:
<?php

namespace Vendor\Addon\ThreadType;

use XF\ThreadType\AbstractHandler;

class TestHandler extends AbstractHandler
{
    public function getTypeIconClass(): string
    {
        return 'fa-user';
    }
}
I don't know a way to make sure this is confirmed working until the next stage which is adding your thread type to existing forum types.
Unless you want to make your own forum type but thats an entirely different thing.

Now make an extension class for the forum type you want to add it to. I believe this only works on the src/XF/ForumType/DiscussionHandler.php though so if you wannt use a different forum type your on your own :P
PHP:
<?php

namespace Vendor\Addon\XF\ForumType;

use XF\Entity\Forum;

class DiscussionHandler extends \XF\ForumType\DiscussionHandler
{
    public function getPossibleCreatableThreadTypes(Forum $forum): array
    {
        return ['article', 'poll', 'question', 'test'];
    }
}

Finally register this with your Admin control panel
Code:
Base class name: XF\ForumType\DiscussionHandler
Extension class name: Vendor\Addon\XF\ForumType\DiscussionHandler

You should now see them here when you go and edit what thread a node can use:
1757700019971.webp

And when you have added that thread type to a node in an post selector
1757700003333.webp

Hope this is what your looking for :)
 
Are you talking about having it appear in the post thread options and in the node edit options?
To get it like this, you need to do a few things.

First off make sure your thread type is being registered correctly.
PHP:
    public function installStep1(): void
    {
        $this->insertThreadType('test', 'Vendor\Addon:Test', 'Vendor/Addon');
    }
What this does is inserts that data into the database and rebuilds the rebuildThreadTypeCache

Before carrying on check the database table xf_thread_type that your new type exists, just to make sure.

Next you'll want to add your thread type handler
PHP:
<?php

namespace Vendor\Addon\ThreadType;

use XF\ThreadType\AbstractHandler;

class TestHandler extends AbstractHandler
{
    public function getTypeIconClass(): string
    {
        return 'fa-user';
    }
}
I don't know a way to make sure this is confirmed working until the next stage which is adding your thread type to existing forum types.
Unless you want to make your own forum type but thats an entirely different thing.

Now make an extension class for the forum type you want to add it to. I believe this only works on the src/XF/ForumType/DiscussionHandler.php though so if you wannt use a different forum type your on your own :P
PHP:
<?php

namespace Vendor\Addon\XF\ForumType;

use XF\Entity\Forum;

class DiscussionHandler extends \XF\ForumType\DiscussionHandler
{
    public function getPossibleCreatableThreadTypes(Forum $forum): array
    {
        return ['article', 'poll', 'question', 'test'];
    }
}

Finally register this with your Admin control panel
Code:
Base class name: XF\ForumType\DiscussionHandler
Extension class name: Vendor\Addon\XF\ForumType\DiscussionHandler

You should now see them here when you go and edit what thread a node can use:
View attachment 326967

And when you have added that thread type to a node in an post selector
View attachment 326966

Hope this is what your looking for :)
Amazing. This is exactly what I was looking for. Thanks so much.
 
Back
Top Bottom