1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XenForo adds-on development

Discussion in 'Papers' started by Stéphane Lenclud, Mar 24, 2017.

  1. Stéphane Lenclud

    Stéphane Lenclud Founder Staff Member

    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:
    1. $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:
    1. <?php
    2. class Slions_Toc_Listeners
    3. {
    4.     /**
    5.     * Must be registered as load_class_bb_code callback
    6.     */
    7.     public static function load_class_bb_code($class, &$extend)
    8.     {
    9.         switch($class)
    10.         {
    11.         // Telling XenForo we extend XenForo_BbCode_Formatter_Base with Slions_Toc_BbCode_Formatter_Base
    12.             case 'XenForo_BbCode_Formatter_Base':
    13.                 $extend[] = 'Slions_Toc_BbCode_Formatter_Base';
    14.             break;
    15.         // Telling XenForo we extend XenForo_BbCode_Formatter_Wysiwyg with Slions_Toc_BbCode_Formatter_Base
    16.             case 'XenForo_BbCode_Formatter_Wysiwyg':
    17.                 $extend[] = 'Slions_Toc_BbCode_Formatter_Base';
    18.             break;
    19.         }
    20.     }
    21. }
    References:
     
    Last edited: Mar 28, 2017

Share This Page