function node_add_body_field
7.x node.module | node_add_body_field($type, $label = 'Body') |
Adds default body field to a node type.
Parameters
$type: A node type object.
$label: The label for the body instance.
Return value
Body field instance.
6 calls to node_add_body_field()
- blog_install in drupal-7.x/
modules/ blog/ blog.install - Implements hook_install().
- DrupalWebTestCase::drupalCreateContentType in drupal-7.x/
modules/ simpletest/ drupal_web_test_case.php - Creates a custom content type based on default settings.
- forum_enable in drupal-7.x/
modules/ forum/ forum.install - Implements hook_enable().
- node_type_form_submit in drupal-7.x/
modules/ node/ content_types.inc - Form submission handler for node_type_form().
- standard_install in drupal-7.x/
profiles/ standard/ standard.install - Implements hook_install().
File
- drupal-7.x/
modules/ node/ node.module, line 586 - 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
function node_add_body_field($type, $label = 'Body') {
// Add or remove the body field, as needed.
$field = field_info_field('body');
$instance = field_info_instance('node', 'body', $type->type);
if (empty($field)) {
$field = array(
'field_name' => 'body',
'type' => 'text_with_summary',
'entity_types' => array('node'),
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => $type->type,
'label' => $label,
'widget' => array('type' => 'text_textarea_with_summary'),
'settings' => array('display_summary' => TRUE),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_default',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
),
),
);
$instance = field_create_instance($instance);
}
return $instance;
}