Pinoniq
Pinoniq

Reputation: 1385

Drupal module node type creation .install vs .module

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 :(

Upvotes: 1

Views: 444

Answers (1)

D34dman
D34dman

Reputation: 1271

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.

Upvotes: 2

Related Questions