There are 2 different ways to create a new content type programmatically.

I am preferring the first method, since my feelings say that is better to maintain (i.e. adding/updating new fields via hook_update_N()) and it suits better in .install file. But, I keep myself asking why it is done other way in Node Example module.

Does anyone know the CONs and PROs of using both methods to create a new content type in code?


Some hooks, like hook_delete are only called on the module that defines the node's content type. If you save content type to a database using node_type_save(), it might not be recognized as "defined by module" - it acts as content types created by user. Unless, of course, you will set $info['module'] to point at your module - in that case created entries should work the same way.


A third method, which is often easier to maintain, especially if your node type will change over time, is to use Features to export the node type, fields, and field instances. You can still add custom code to the exported Features module, and Features will preserve that custom code (and any additional files) in future exports.

I used to use the .install file method for a long time, but Features' stability and UI/drush integration is good enough now that it saves me a lot of time manually getting the field info and node type info.

If you make changes to the node type/fields/etc., and re-export the feature module, you can update the feature in the UI or using drush feature-revert or features-revert-all.


There will be no issue with that...with update method you can create the new content types...

  • Do you really think this is an ANSWER to the question of the cons and pros the OP is asking?
    – Sk8erPeter
    Sep 13 '13 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.