XenForo adds-on development

Assuming you have a working XenForo installation with which you want to start developing add-ons, you first need to enable debug mode through your XenForo configuration.
To do so, add the following line to /library/config.php :
PHP:
$config['debug'] = 1;

Reload your Administrator Control Panel (ACP) to notice you now have a Development tab.
upload_2017-3-24_21-14-59.png

It comes with the following side bar:
upload_2017-3-24_21-17-6.png
Debug mode is essential as XenForo ACP provides developer with tools and helps guiding you through the process of developing your own add-on. You probably have notice the lack of developer documentations but in fact most of it can be found through your ACP once you've enabled debug mode.

We are now going to take you through the process of creating an add-on called Slions - Table Of Content.

Click on Create Add-on. You will get a form like the following one:
upload_2017-3-24_21-36-1.png
Once your add-on is created you need register listeners so that it can hook-in with XenForo core framework. Go to Code Event Listener and create a new one such as:
upload_2017-3-24_21-24-16.png
Notice that if you try to save your event listener without the proper PHP file being available on your server you will get the following error message:
upload_2017-3-24_21-28-20.png

In our case you will need to have uploaded /library/Slions/Toc/Listeners.php :
PHP:
<?php
class Slions_Toc_Listeners
{
    /**
    * Must be registered as load_class_bb_code callback
    */
    public static function load_class_bb_code($class, &$extend)
    {
        switch($class)
        {
        // Telling XenForo we extend XenForo_BbCode_Formatter_Base with Slions_Toc_BbCode_Formatter_Base
            case 'XenForo_BbCode_Formatter_Base':
                $extend[] = 'Slions_Toc_BbCode_Formatter_Base';
            break;
        // Telling XenForo we extend XenForo_BbCode_Formatter_Wysiwyg with Slions_Toc_BbCode_Formatter_Base
            case 'XenForo_BbCode_Formatter_Wysiwyg':
                $extend[] = 'Slions_Toc_BbCode_Formatter_Base';
            break;
        }
    }
}

References:
 
Last edited:
Back
Top