Modules could previously (and preferably) create new node types by implementing hook_node_info()
. However, as part of the conversion of node type and field definitions to CMI, hook_node_info()
has been removed. Use node_type_save() in hook_install()
instead.
Previous in node_example.module:
<?php
/**
* Implements hook_node_info().
*
* We use hook_node_info() to define our node content type.
*/
function node_example_node_info() {
// We define the node type as an associative array.
return array(
'node_example' => array(
'name' => t('Example Node Type'),
// 'base' tells Backdrop the base string for hook functions.
// This is often the module name; if base is set to 'mymodule',
// Backdrop would call mymodule_insert() or similar for node
// hooks. In our case, the base is 'node_example'.
'base' => 'node_example',
'description' => t('This is an example node type with a few fields.'),
'title_label' => t('Example Title'),
// We'll set the 'locked' attribute to TRUE, so users won't be
// able to change the machine name of our content type.
'locked' => TRUE,
),
);
}
?>
Now, in node_example.install:
<?php
/**
* Implements hook_install().
*/
function node_example_install() {
$node_example_node_type = array(
'type' => 'node_example',
'name' => t('Example Node Type'),
'base' => 'node_content',
'description' => t('This is an example node type with a few fields.'),
'custom' => 1,
'modified' => 1,
'locked' => 0,
'is_new' => TRUE,
'settings' => array(
'promote_enabled' => FALSE,
),
);
$node_example_node_type = node_type_set_defaults($node_example_node_type);
node_type_save($node_example_node_type);
node_add_body_field($node_example_node_type);
}
?>
Introduced in branch:
1.0.x
Introduced in version:
1.0.0
Impacts:
Module developers
Related Github Issues: