function _comment_body_field_create in Drupal 7
Creates a comment_body field instance for a given node type.
2 calls to _comment_body_field_create()
- comment_modules_enabled in modules/
comment/ comment.install - Implements hook_modules_enabled().
- comment_node_type_insert in modules/
comment/ comment.module - Implements hook_node_type_insert().
File
- modules/
comment/ comment.module, line 362 - Enables users to comment on published content.
Code
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);
}
}