node_add_body_field

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 node_add_body_field($type, $label = 'Body')

Add 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.

▾ 9 functions call 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_example_install in examples/node_example/node_example.install
Implements hook_install().
node_type_form_submit in modules/node/content_types.inc
Form submission handler for node_type_form().
simpletest_example_install in examples/simpletest_example/simpletest_example.install
Implements hook_install().
simpletest_example_update_7001 in examples/simpletest_example/simpletest_example.install
Adds a body field to the simpletest_example node type.
standard_install in profiles/standard/standard.install
Implements hook_install().
_book_install_type_create in modules/book/book.install

Code

modules/node/node.module, line 552

<?php
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;
}
?>