Edit with an addon the Forum.php NodeHandler

Hi!

I'm new to XenForo, so I don't have much experience with this platform and his plugins.

I'm trying to edit the /library/XenForo/NodeHandler/Forum.php file with a plugin (because I have many files to edit, to get a rendering depth > of 2) and in particular this function:

PHP:
public function renderNodeForTree(XenForo_View $view, array $node, array $permissions,
        array $renderedChildren, $level
    )
    {
        $templateLevel = ($level <= 2 ? $level : 'n');

        return $view->createTemplateObject('node_forum_level_' . $templateLevel, array(
            'level' => $level,
            'forum' => $node,
            'renderedChildren' => $renderedChildren
        ));
    }

(I need to edit the "2" with "3").

How to achieve this with a plugin?

I'm trying following this guide: https://xenforo.com/community/threads/creating-an-addon.5416/ and I ended getting 2 files:

library/NodeLvl/XenForo/NodeHandler/NodeLvl.php
PHP:
<?php

class NodeLvl_XenForo_NodeHandler_NodeLvl extends XenForo_NodeHandler_Forum
{

    public function renderNodeForTree(XenForo_View $view, array $node, array $permissions,
        array $renderedChildren, $level
    )
    {
        $templateLevel = ($level <= 3 ? $level : 'n');

        return $view->createTemplateObject('node_forum_level_' . $templateLevel, array(
            'level' => $level,
            'forum' => $node,
            'renderedChildren' => $renderedChildren
        ));
    }

}
?>

library/NodeLvl/Listener/LoadClassController.php
PHP:
<?php

class NodeLvl_Listener_LoadClassController
{
        public static function loadClassListener($class, &$extend)
        {

                if ($class == 'XenForo_NodeHandler_Forum')
                {
                        $extend[] = 'NodeLvl_XenForo_NodeHandler_NodeLvl';
                }

        }

}

?>

But nothing seems to happen, any advice?
 
Last edited:
Your extend is trying to locate file NodeLvl.php in NodeLvl/XenForo/NodeHandler/NodeLvl.php but your file is saved in NodeLvl/XenForo/NodeHandler.php?

Your class name needs to match the directory structure or else the autoloader can't find it.
 
Also, youre extending the wrong class in you extension. You should be extending XFCP_classname.

Liam
 
Also you should probably utilise the edit hint in the code event listeners and strip the if statement out of your listener.
 
Your extend is trying to locate file NodeLvl.php in NodeLvl/XenForo/NodeHandler/NodeLvl.php but your file is saved in NodeLvl/XenForo/NodeHandler.php?

Your class name needs to match the directory structure or else the autoloader can't find it.

Sorry, I writed wrong in the topic, the directory is library/NodeLvl/XenForo/NodeHandler/NodeLvl.php
 
That's the code "fixed":

library/NodeLvl/XenForo/NodeHandler/NodeLvl.php
PHP:
<?php

class NodeLvl_XenForo_NodeHandler_NodeLvl extends XFCP_NodeLvl_XenForo_NodeHandler_NodeLvl
{

    public function renderNodeForTree(XenForo_View $view, array $node, array $permissions,
        array $renderedChildren, $level
    )
    {
        $templateLevel = ($level <= 3 ? $level : 'n');

        return $view->createTemplateObject('node_forum_level_' . $templateLevel, array(
            'level' => $level,
            'forum' => $node,
            'renderedChildren' => $renderedChildren
        ));
    }

}
?>

library/NodeLvl/Listener/LoadClassController.php
PHP:
<?php


class NodeLvl_Listener_LoadClassController
{
        public static function loadClassListener($class, &$extend)
        {

                        $extend[] = 'NodeLvl_XenForo_NodeHandler_NodeLvl';
         
        }

}

?>

Here if I strip out the if statement as @James advised, I get this error in all the board:
Code:
Fatal error: Cannot redeclare class XFCP_NodeLvl_XenForo_NodeHandler_NodeLvl in /var/www/html/foro/library/XenForo/Application.php(528) : eval()'d code on line 1

This is the Event Code Listener:
be3792682eacf8079ad4d5bb0d25ebfb.png


Anyway, If I reintroduce the If statement, nothing changes :(
 
The class you try to extend is not a controller. So you should not listen to the „load_class_controller“ event but to „load_class“.
 
Top Bottom