1 comment.module | _comment_body_field_create($info) |
Creates a comment_body field instance for a given node type.
Parameters
$info: An object representing the content type. The only property that is currently used is $info->type, which is the machine name of the content type for which the body field (instance) is to be created.
File
- core/
modules/ comment/ comment.module, line 380 - 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);
}
}