Addons Clashing

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

Fatal error: Call to undefined method PHCTags_BbCode_Formatter_Base::render() in /home/phphelpc/public_html/library/XenForo/BbCode/TextWrapper.php on line 117

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.
 
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.
 
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.
 
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')
 
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.
 
This is the error

Fatal error: Call to undefined method PHCTags_BbCode_Formatter_Base::render() in /home/phphelpc/public_html/library/XenForo/BbCode/TextWrapper.php on line 117

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 $hookParams, XenForo_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;
        }
    }
} 
?>
 
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.

Fatal error: Call to undefined method XenForo_BbCode_Formatter_Base::render() in /home/phphelpc/public_html/library/XenForo/BbCode/TextWrapper.php on line 117


That's with PHCTags disabled.
 
Attempt reuploading your files, that error should happen. Do you have any other add ons installed?
 
You will then need to disable add-ons one by one to figure our which one isn't working.
 
Back
Top Bottom