hook_node_info

function hook_node_info

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 blog module uses it to define a blog node-type named "Blog entry." 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 machine-readable type name 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 name for implementations of node-type-specific hooks that respond to this node type. Base is usually the name of the module or 'node_content', but not always. See Node API hooks for more information.
  • 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

File

modules/node/node.api.php, line 916
Hooks provided by the Node module.

Code

function hook_node_info() {
  return array(
    'blog' => array(
      'name' => t('Blog entry'),
      'base' => 'blog',
      'description' => t('Use for multi-user blogs. Every user gets a personal blog.'),
    )
  );
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_info/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部