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

Addons Clashing

Discussion in 'XenForo Development Discussions' started by Daniel Hood, Aug 1, 2013.

  1. Daniel Hood

    Daniel Hood Well-Known Member

    I have two addons, both created by me:

    One listens to "load_class_bb_code" with this code:

    PHP:
    if ($class == 'XenForo_BbCode_Formatter_Base')
            {
                
    $extend[] = 'PHCTags_BbCode_Formatter_Base';
            }
    In PHCTags_BbCode_Formatter_Base I have

    PHP:
        class PHCTags_BbCode_Formatter_Base extends XFCP_PHCTags_BbCode_Formatter_Base
    and then my other addon is trying to call:

    PHP:
    $bbCodeParser XenForo_BbCode_Formatter_Base::create('Base');
              
    XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages($hookParams['threads'], $bbCodeParser);
    It's

    PHP:
    XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages(
    that results in this error

    Any ideas what I did wrong? I assume I extended a wrong class or something? Let me know if I didn't give enough code.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    It's hard to say without seeing more of your code but are you extending existing functions in those extended classes or are you creating new functions?

    Because if you're extending existing functions you must always call the parent.

    e.g.

    PHP:
    class YourClass_BbCode_Formatter_Base extends XFCP_YourClass_BbCode_Formatter_Base
    {
        public function 
    existingMethod($param, array $stuff)
        {
            
    parent::existingMethod($param, array $stuff);

            
    // Your code here will run after the parent has run.
        
    }
    }
    Or you can catch the parent in a variable and return it at the end.
     
  3. Daniel Hood

    Daniel Hood Well-Known Member

    I made one new function and one existing. I called parent:: first though in the existing function. I did absolutely nothing to the render function.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Only other thing I can think of...

    The code example from the listener you posted seems fine.

    What about the other listener?

    A common mistake is using

    PHP:
    if ($class 'Some_Class_Name'
    Instead of

    PHP:
    if ($class == 'Some_Class_Name')
     
  5. Daniel Hood

    Daniel Hood Well-Known Member

    The other one doesn't listen to bbcode just the template hook. I don't think it's that due to it working until I attempt to use bbcode helper.

    I'm currently not at home so I'm testing from the phone. sorry for the lack of cod. I'll post more when I get there.
     
  6. Daniel Hood

    Daniel Hood Well-Known Member

    This is the error

    This is PHCTags_BbCode_Formatter_Base

    PHP:
    <?php
        
    class PHCTags_BbCode_Formatter_Base extends XFCP_PHCTags_BbCode_Formatter_Base
        
    {
            public function 
    renderHashTag($matches)
            {            
               
    // Addon's Code, this function doesn't exist by default so no need to call parent.
            
    }
            public function 
    renderString($string, array $rendererStates, &$trimLeadingLines)
        {
                
    $string parent::renderString($string$rendererStates$trimLeadingLines);
                
    // Addon's Code \\
                
    return $string;
        }
        }
    ?>

    This is the new addon's listener.

    PHP:
    <?php
    class XMPromoteThreads_Listen
    {
        public static function 
    TemplateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if (
    $hookName == 'forum_list_nodes')
            {
                
    $globalModel XenForo_Model::create('XMPromoteThreads_Model');
               
                
    $hookParams['threads'] = $globalModel->load();           
               
               
    $bbCodeParser XenForo_BbCode_Formatter_Base::create('Base');
               
                
    XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages($hookParams['threads'], $bbCodeParser);
               
                
    $contents $template->create('XMPromotedThreads'$hookParams) . $contents;
            }
        }

    ?>
     
  7. Daniel Hood

    Daniel Hood Well-Known Member

    Just decided to see if I was even on base with this being what caused the error and I don't think so. It appears you can't use bbcode in listeners.



    That's with PHCTags disabled.
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    Attempt reuploading your files, that error should happen. Do you have any other add ons installed?
     
  9. Daniel Hood

    Daniel Hood Well-Known Member

    Some, none that include bbcode though. Which files should I reupload?
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    All of the XenForo ones wouldn't hurt. But specifically the BbCode related ones in library/XenForo.
     
    Daniel Hood likes this.
  11. Daniel Hood

    Daniel Hood Well-Known Member

    Oh, they're fine. the entire site is fine as soon as that listener is disabled. All bbcode and stuff works.
     
  12. Jeremy

    Jeremy XenForo Moderator Staff Member

    You will then need to disable add-ons one by one to figure our which one isn't working.
     

Share This Page