function hook_node_info

7.x node.api.php hook_node_info()
6.x node.php hook_node_info()

Define module-provided node types.

This is a hook used by node modules. This hook is required for modules to define one or more node types. It is called to determine the names and the attributes of a module's node types.

Only module-provided node types should be defined through this hook. User- provided (or 'custom') node types should be defined only in the 'node_type' database table, and should be maintained by using the node_type_save() and node_type_delete() functions.

Return value

An array of information on the module's node types. The array contains a sub-array for each node type, with the machine-readable type name as the key. Each sub-array has up to 10 attributes. Possible attributes:

  • "name": the human-readable name of the node type. Required.
  • "module": a string telling Drupal how a module's functions map to hooks (i.e. if module is defined as example_foo, then example_foo_insert will be called when inserting a node of that type). This string is usually the name of the module in question, but not always. Required.
  • "description": a brief description of the node type. Required.
  • "help": text that will be displayed at the top of the submission form for this content type. Optional (defaults to '').
  • "has_title": boolean indicating whether or not this node type has a title field. Optional (defaults to TRUE).
  • "title_label": the label for the title field of this content type. Optional (defaults to 'Title').
  • "has_body": boolean indicating whether or not this node type has a body field. Optional (defaults to TRUE).
  • "body_label": the label for the body field of this content type. Optional (defaults to 'Body').
  • "min_word_count": the minimum number of words for the body field to be considered valid for this content type. Optional (defaults to 0).
  • "locked": boolean indicating whether the machine-readable name of this content type can (FALSE) or cannot (TRUE) be edited by a site administrator. Optional (defaults to TRUE).

The machine-readable name of a node type should contain only letters, numbers, and underscores. Underscores will be converted into hyphens for the purpose of constructing URLs.

All attributes of a node type that are defined through this hook (except for 'locked') can be edited by a site administrator. This includes the machine-readable name of a node type, if 'locked' is set to FALSE.

For a detailed usage example, see node_example.module.

Related topics

3 functions implement hook_node_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

blog_node_info in drupal-6.x/modules/blog/blog.module
Implementation of hook_node_info().
forum_node_info in drupal-6.x/modules/forum/forum.module
Implementation of hook_node_info().
poll_node_info in drupal-6.x/modules/poll/poll.module
Implementation of hook_node_info().
2 invocations of hook_node_info()
node_type_reset in drupal-6.x/modules/node/content_types.inc
Resets all of the relevant fields of a module-defined node type to their default values.
_node_types_build in drupal-6.x/modules/node/node.module
Builds and returns the list of available node types.

File

documentation-6.x/developer/hooks/node.php, line 68
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_node_info() {
  return array(
    'book' => array(
      'name' => t('book page'),
      'module' => 'book',
      'description' => t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it."),
    )
  );
}