| 7 node.module | node_type_set_defaults($info = array()) |
| 8 node.module | node_type_set_defaults($info = array()) |
Sets the default values for a node type.
The defaults are appropriate for a type defined through hook_node_info(), since 'custom' is TRUE for types defined in the user interface, and FALSE for types defined by modules. (The 'custom' flag prevents types from being deleted through the user interface.) Also, the default for 'locked' is TRUE, which prevents users from changing the machine name of the type.
Parameters
$info: An object or array containing values to override the defaults. See hook_node_info() for details on what the array elements mean.
Return value
A node type object, with missing values in $info set to their defaults.
File
- modules/
node/ node.module, line 769 - The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.
Code
<?php
function node_type_set_defaults($info = array()) {
$info = (array) $info;
$new_type = $info + array(
'type' => '',
'name' => '',
'base' => '',
'description' => '',
'help' => '',
'custom' => 0,
'modified' => 0,
'locked' => 1,
'disabled' => 0,
'is_new' => 1,
'has_title' => 1,
'title_label' => 'Title',
);
$new_type = (object) $new_type;
// If the type has no title, set an empty label.
if (!$new_type->has_title) {
$new_type->title_label = '';
}
if (empty($new_type->module)) {
$new_type->module = $new_type->base == 'node_content' ? 'node' : '';
}
$new_type->orig_type = isset($info['type']) ? $info['type'] : '';
return $new_type;
}
?> Login or register to post comments
Comments
What's about these
What's about these attributes?
<?php'has_body' => TRUE,
'body_label' => $t('My example body')
?>
body is a field instance in D7
in Drupal 7 the body is just another field instance, it is no longer treated as a special case attached to the node like it was in previous versions.
use node_add_body_field($type, $label = 'Body')
'Custom'
Editing out my verbose and confusing question that should have been an issue instead, like this one: http://drupal.org/node/1027630
Thanks ilo and jhodgdon!