Same name and namespace in other branches
  1. 10 core/modules/node/node.module \node_add_body_field()
  2. 8.9.x core/modules/node/node.module \node_add_body_field()
  3. 9 core/modules/node/node.module \node_add_body_field()

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 modules/blog/blog.install
Implements hook_install().
DrupalWebTestCase::drupalCreateContentType in modules/simpletest/drupal_web_test_case.php
Creates a custom content type based on default settings.
forum_enable in modules/forum/forum.install
Implements hook_enable().
node_type_form_submit in modules/node/content_types.inc
Form submission handler for node_type_form().
standard_install in profiles/standard/standard.install
Implements hook_install().

... See full list

File

modules/node/node.module, line 587
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;
}