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

Creating custom node type, need help with errors/listeners

Discussion in 'XenForo Development Discussions' started by Bloodcinder, Jul 14, 2014.

  1. Bloodcinder

    Bloodcinder Well-Known Member

    I'm trying to create a custom node type for reasons that I won't go into here. Let's just pretend I'm developing an add-on called AddOn to create a custom node type called Gadget.

    Here are the steps I've undertaken so far, by analyzing how Xenforo's LinkForum node type works. I've also looked at some Waindigo add-ons that add custom node types.

    1. I've copied all of the Xenforo_*_LinkForum classes and modified them into Bloodcinder_AddOn_*_Gadget classes. (That is to say, I've copied LinkForum's ControllerPublic, ControllerAdmin, DataWriter, Model, NodeHandler, Route_Prefix, and Route_PrefixAdmin and replaced all class names appropriately and all terminology related to link-forums has been replaced with terms appropriate to gadgets.)

    2. I've created an xf_gadget table with appropriate fields and created a row in xf_node_type to refer to it, with class names for the three different class fields as labeled by Step 1 and all fields filled consistently.

    3. I've added route prefixes using the admin panel to complement the route prefixes already there for link-forums.

    4. I've added an administrative navigation entry to Create New Gadget, also based off of the one for Create New Link Forum.

    5. I've added all the necessary phrases and templates corresponding to the link-forum phrases and templates, modified for gadgets.

    6. If it's not obvious... all of these are assigned to my AddOn by Bloodcinder add-on.

    As of now, my admin panel is fully functional for creating the new Gadget nodes, getting them to display in the node tree, and getting the correct changes into the xf_gadget, xf_node_type, and xf_node databases for any created Gadgets. To reiterate, everything works exactly correct on the admin side.

    Also as of now, if I navigate directly to the public URL of a Gadget node, it will display correctly (a test page right now). But if I try to view the front page of the site with that Gadget node stored as a visible child of anything there, I get a crash in Xenforo_Model_Node at line 521 telling me "Fatal Error: Class name must be a valid object or a string" as if it does not know where the gadget model is.

    I can't figure this error out, because I have been completely consistent with all my naming. (Let's assume that typos are not the issue. I've triple and quadruple checked my scripts and I'm fairly certain I've accurately reused and changed the necessary code from LinkForums all the way through and that the scripts that I have written are fine. If it turns out the problem is related to a stupid code oversight like this, I'll be very ashamed.)

    I think my trouble is that I need Listener(s), and so far I don't have any. Because...

    I don't know what Listeners to setup. There are no LinkForum examples to go on, since they are core Xenforo (unless I don't know where to look). Looking at Waindigo's Library and SocialGroups add-ons (which provide custom node types) doesn't help me a lot because he uses his own inheritance hierarchy in the listener scripts and there are dozens of listeners, and so I can't figure out what I need for my purposes. And the listener scripts for other add-ons don't seem to be helping me any because they don't work with custom node types, so I can't intuit a solution for my particular issue.

    I don't even particularly understand the necessity of Listeners. I don't mean that I don't know how to set them up: I mean I don't know when and why to set them up. I can't really find any documentation that persuades me to use them, only documentation that shows me how to use them. So I'm left trying to guess which of my classes need them and which don't.

    Since the entire admin side works, I'm guessing none of those classes need listeners, which confuses me because I don't understand how the admin side magically incorporates my classes whereas the public side does not. Nevertheless, it seems like only the public side is missing something, apparently related to the node model.

    So I'm not certain what Listeners I need to add to get this to work. I may have provided too much information and the fix is very easy. I don't know. But any insight from Xenforo devs is appreciated if you can help me figure out what Listeners I need.

    Thanks, and if I've omitted any necessary information, please let me know so I can correct it.
     
    Last edited: Jul 15, 2014
  2. Bloodcinder

    Bloodcinder Well-Known Member

    I found the solution after trial and error.

    For the benefit of anybody who may want to know what the solution was, in order to make Bloodcinder_AddOn_ControllerPublic_Gadget accessible from the front page, I had to add a listener for Xenforo_ControllerPublic_Forum.
     
    Mick West likes this.

Share This Page