How to overwrite an NodeHandler

EsKuel

Member
Hello everyone !

I'm trying to do a little addon that need to extend XenForo_NodeHandler_Abstract which is not possible.
I heard that we can overwrite an Handler but I didn't found any documentation or explanation about it.

Can somebody explain how to overwrite this or send me a piece of code ?

Thanks for your help :)
 
The locations of the NodeHandler's are stored in the xf_content_type_field table (and in serialized form in the xf_content_type table). Since there is no load_class_node_handler code-event, your best bet is to run a query to change the node handler location in the database (and then run the rebuildContentTypeCache() method of XenForo_Model_ContentType:
PHP:
XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache();
You can then extend the old NodeHandler from the new one.
Unfortunately, this way of extending is quite selfish as only one add-on can really do this independently without messing up other add-ons with the same idea.

In your PM to me, you mentioned my Library add-on. This is a different case, because I have created my own node type (library) and then created a new entry in the xf_content_type table and a new NodeHandler in the xf_content_type_field table, in the same way as described above.
In contrast to the above, this is very unselfish, providing that you choose a unique name for your content type.

Hope this helps.
 
Sorry, am talking rubbish.

It's in the xf_node_type table.

Just spotted your post here:
http://xenforo.com/community/thread...-get-data-needed-via-addon.32763/#post-413635

Might be easier to create your own load_class_node_handler code event by extending XenForo_Model_Node and replacing getNodeHandlersForNodeTypes() with:
PHP:
public function getNodeHandlersForNodeTypes(array $nodeTypeIds)
{
    $nodeTypes = $this->getAllNodeTypes();
    $output = array();
    foreach ($nodeTypeIds AS $nodeTypeId)
    {
        $class = isset($nodeTypes[$nodeTypeId]) ? $nodeTypes[$nodeTypeId]['handler_class'] : '';
        $output[$nodeTypeId] = XenForo_Application::resolveDynamicClass($class, 'node_handler');
    }
    return $output;
}

Then you can extend all the NodeHandlers you like, perhaps using eval() to create the extender classes automatically?
 
Thanks for taking time to help me.
I know that overwrite the NodeHandler is not a good solution but I don't find any other solution.

In fact I just want to add the display_style_group_id to the $forum.lastPost variable on the index board, so I extended the Forum Model and it's working well.
But it's not working for forum in subcategory because the getExtraForumDataForNodes will search the display_style_group_id for every forums and it's in NodeHandler that XenForo keep the last display_style_group_id in _getForumLikePushableData.

Well, I think it's not really clear, I'll try to search another solution and if I don't find it, I'll overwrite NodeHandler :)

Thanks !
 
Back
Top Bottom