By Daren Schwenke on
I have created multiple node types for a recent project, that are all pretty much dependant on one another to function as they form a heirarchy.
I've put them all in the same project as seperate modules for the installer, but if I set them up as all dependant on each other, you can never uninstall them. :)
For simplicities sake, is it possible to have multiple node types and the corresponding _hooks for each to be all within one module?
Thank you for your time.
Comments
Yes, it's certainly
Yes, it's certainly possible. The trick is correctly defining multiple types in hook_node_info().
Here's an example based on a module I'm developing with 2 types:
You'll notice that neither of the "module" attributes are the same as the name of the module (synth_products.module), so for the node type hooks, I implement functions like: synth_transaction_load() and synth_product_load(), but the usual module hooks are implemented like synth_products_menu().
Note also, that the "module" attribute does NOT have to be the same as the node type. So, all your different node type could get loaded/saved using the same one set of hooks (as the new code in node module does for user-defined types).
---
Work: BioRAFT
Thank you.
I tried what you said earlier in my dev of these modules, but I must have had some errors. Specifically the parts that relate to the main module name versus the individual node types were confusing me. I think I understand now. Thank you.
Multiple block types not showing up.
Ok. Basically I took my three working modules, put all three node types in main_module_node_info(), and copied the rest of the code into the one .module file keeping the same naming.
When I do this, only the hook_block type defined as related to the main_module now will show up in the blocks menu.
The others are not in there anymore...
Can the module define more than one block type?
EDIT: I found my own answer here just after I wrote this. http://drupal.org/node/84213 which references the hook_block api page: http://api.drupal.org/api/HEAD/function/hook_block
What I didn't get before is that the first parameter in the array returned from the 'list' op defines what the DELTA's will be used for later.... now I get it..