The task is similar to the example provided http://api.drupal.org/api/drupal/developer--examples--node_example.module/7 but with usage Field API.

Only way I have found is to add node_type_save instructions in hook_install() and than in hook_node_type_insert() add required fields to the created content type (example http://drupal.org/node/474420).

But I think it is not the best way of doing this as we do not use hook_node_info() as it is designed for creating module specific node types.

Please advise the best way of doing the task.

Thank you!

Comments

yched’s picture

I don't think I get the question. Field API is not about creating node types.
Node types are created with node_type_save() as in D6. Only difference, being polished in #553306: Make nodes have no body field by default. Remove deprecated APIs for body field (see comment #80), is that when creating a new type, node_type_save() will automatically attach instances of the 'body' and 'title' fields (unless specified otherwise in the arguments).

Then you can add fields to the node type as in the example you point to (http://drupal.org/node/474420).

ygerasimov’s picture

Status: Active » Closed (won't fix)

Yves, I understand that Fields API are not about creating node types. I can create them using node_type_save or using hook_node_info. It would be nice if there is the way to attach fields after hook_node_info created new node type.

But anyway it can be done using node_type_save placing it in hook_enable of the module and than attach all required fields.