How do you add fields to module created content types?

hook_node_info works and creates a content type. I followed an endless maze of examples trying to add the body and a couple of other fields to the content type created by hook_node_info. Nothing worked. All the examples of adding fields appear to work only if you create the content type by hand through the admin UI.

hook_node_info needs a roadmap to the next step.
What is the next step after hook_node_info to add the body field?
What is the next step after hook_node_info to add other fields?

CommentFileSizeAuthor
#4 948272.patch485 bytesamateescu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Category: feature » support
Status: Active » Fixed

That type of information belongs in either (a) the Examples for Developers project, or (b) a Handbook page. Not in hook_node_info().

And I'm actually reasonably certain it already exists in http://drupal.org/project/examples already. Please check out the examples there, and open an issue on that project if you think one of the examples needs more detail, more information, etc.

peterx’s picture

Status: Fixed » Needs review

hook_node_info has a Related topics section that I thought would lead somewhere useful. Node API Hooks leads to node creation information, not node type creation. Hooks leads to a long trail of disconnected examples and those examples no longer use hook_node_info. A link to a node type creation tutorial page using hook_node_info would be useful.

http://drupal.org/project/examples points to node_example, the same example I reach from the Related topics link. node_example no longer uses hook_node_info. There are several posts saying hook_node_info is dropped in Drupal 7. The Book module no longer uses hook_node_info.

http://drupal.org/node/642862 mentions the problem. node_example shows node type creation using node_type_save instructions in hook_install() and hook_node_type_insert() to add fields.

Perhaps the documentation should suggest the new way of doing things and direct people to whatever replaces hook_node_info.

jhodgdon’s picture

Title: Documentation problem with hook_node_info » hook_node_info() doc shouldn't link to node example module any more
Category: support » bug
Status: Needs review » Active
Issue tags: +Novice

hook_node_info has not been dropped in Drupal 7. The core Blog and Poll modules both use it, for one thing. The Node API Hooks page does mention hook_node_info() at the top, and it is still the accepted way for a module to define a node type.

I'm sorry that the node example module has been changed so that it no longer uses hook_node_info(). I wasn't part of that decision, and it is unfortunate in my opinion. I wasn't aware of that until just now. The core Blog and Poll modules still provide examples of how to use it. The node example module has moved to a different model, where they're providing a node type that uses the field API, so it can be modified in the user interface. Anyway, use Blog and Poll modules in Core as examples.

So we shouldn't reference the node example module in the documentation block for hook_node_info any more, so that is a documentation bug that should be fixed. We just need to remove the line that says

For a detailed usage example, see node_example.module.

That's a good project for a novice contributor...

amateescu’s picture

Status: Active » Needs review
FileSize
485 bytes

Here it is.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

That's it, thanks!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed #4 to HEAD. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Novice

Automatically closed -- issue fixed for 2 weeks with no activity.