1
votes

After browsing the net for over an hour my question remains. What is the 'correct' way to create a node type in a module.

.install: hook_install() gives you the possibility to create node_types using the node_type_save() hook...

.module using hook_node_info() you can add node type(s).

What are the pro's and cons of those 2 methods? Is there in fact a different? What happens when you uninstall the module? How should one manage updates in both cases? The drupal docu hasn't been really helpfull for me :(

1
The best way is to use hook_node_info. You can find more documentation on api.drupal.org. There is no other way! - Bhavin Joshi
Its saving a node, you need to define the type first! If not type defined how would you relate a node to non-existent type? Did you read this: type: A string giving the machine name of the node type. If you think it works without defining the node type first, why don't you give it a try? Also check the 'code' on that page! - Bhavin Joshi
you can create it in both. Drupal Core book module creates it in hook_install. But its more common practice to do so in hook_node_info(). - D34dman
if you implement using hook_node_info() you are more complaint with the way drupal works. For example node_type_rebuild() will only work with hook_node_info() and not node_type_save() - D34dman

1 Answers

2
votes

you can create node_types using both node_type_save() and hook_node_info().

Drupal Core book module creates it in hook_install. But its more common practice to do so in hook_node_info() or hook_entity_info() ( node module uses hook_entity_info() ).

if you implement using hook_node_info() you are more complaint with the way drupal works. For example node_type_rebuild() will only work with values defined in hook_node_info() and not node_type_save().

Imo you should be using hook_node_info() or hook_entity_info() and let drupal core handle the rest.