_comment_body_field_create

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 _comment_body_field_create($info)

Creates a comment_body field instance for a given node type.

Code

modules/comment/comment.module, line 361

<?php
function _comment_body_field_create($info) {
  // Create the field if needed.
  if (!field_read_field('comment_body', array('include_inactive' => TRUE))) {
    $field = array(
      'field_name' => 'comment_body', 
      'type' => 'text_long', 
      'entity_types' => array('comment'),
    );
    field_create_field($field);
  }
  // Create the instance if needed.
  if (!field_read_instance('comment', 'comment_body', 'comment_node_' . $info->type, array('include_inactive' => TRUE))) {
    field_attach_create_bundle('comment', 'comment_node_' . $info->type);
    // Attaches the body field by default.
    $instance = array(
      'field_name' => 'comment_body', 
      'label' => 'Comment', 
      'entity_type' => 'comment', 
      'bundle' => 'comment_node_' . $info->type, 
      'settings' => array('text_processing' => 1), 
      'required' => TRUE, 
      'display' => array(
        'default' => array(
          'label' => 'hidden', 
          'type' => 'text_default', 
          'weight' => 0,
        ),
      ),
    );
    field_create_instance($instance);
  }
}
?>