function hook_node_info

Define module-provided node types.

This hook allows a module to define one or more of its own node types. For example, the forum module uses it to define a forum node-type named "Forum topic." The name and attributes of each desired node type are specified in an array returned by the hook.

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 defining the module's node types. The array contains a sub-array for each node type, with the the machine name of a content type as the key. Each sub-array has up to 10 attributes. Possible attributes:

  • name: (required) The human-readable name of the node type.
  • base: (required) The base string used to construct callbacks corresponding to this node type (for example, if base 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, but not always.
  • description: (required) A brief description of the node type.
  • help: (optional) Help information shown to the user when creating a node of this type.
  • has_title: (optional) A Boolean indicating whether or not this node type has a title field.
  • title_label: (optional) The label for the title field of this content type.
  • locked: (optional) A Boolean indicating whether the administrator can change the machine name of this type. FALSE = changeable (not locked), TRUE = unchangeable (locked).

The machine 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.

Related topics

2 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.

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

File

drupal/core/modules/node/node.api.php, line 933
Hooks provided by the Node module.

Code

function hook_node_info() {
  return array(
    'forum' => array(
      'name' => t('Forum topic'),
      'base' => 'forum',
      'description' => t('A <em>forum topic</em> starts a new discussion thread within a forum.'),
      'title_label' => t('Subject'),
    ),
  );
}