1 comment.module | comment_form_node_type_form_alter(&$form, $form_state) |
Implements hook_form_FORM_ID_alter().
File
- core/
modules/ comment/ comment.module, line 1084 - Enables users to comment on published content.
Code
function comment_form_node_type_form_alter(&$form, $form_state) {
$node_type = $form['#node_type'];
if (isset($form['type'])) {
$form['comment'] = array(
'#type' => 'fieldset',
'#title' => t('Comment settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#access' => user_access('administer comment settings'),
'#attributes' => array(
'class' => array('comment-node-type-settings-form'),
),
'#attached' => array(
'js' => array(backdrop_get_path('module', 'comment') . '/js/comment.admin.js'),
),
'#weight' => 25,
);
// Unlike comment_form_node_form_alter(), all of these settings are applied
// as defaults to all new nodes. Therefore, it would be wrong to use #states
// to hide the other settings based on the primary comment setting.
$form['comment']['comment_default'] = array(
'#type' => 'radios',
'#title' => t('Default comment setting for new content'),
'#default_value' => $node_type->settings['comment_default'],
'#options' => array(
COMMENT_NODE_OPEN => t('Open comments'),
COMMENT_NODE_CLOSED => t('Closed comments'),
),
);
$form['comment']['comment_per_page'] = array(
'#type' => 'number',
'#title' => t('Comments per page'),
'#default_value' => $node_type->settings['comment_per_page'],
'#required' => TRUE,
'#min' => 10,
'#max' => 1000,
'#step' => 10,
);
$form['comment']['comment_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Show comment replies in a threaded list'),
'#default_value' => $node_type->settings['comment_mode'],
'#description' => t('A threaded list differs from a chronological list in that each comment follows its parent, and is usually indented.'),
);
$form['comment']['comment_anonymous'] = array(
'#type' => 'select',
'#title' => t('Anonymous commenting'),
'#default_value' => $node_type->settings['comment_anonymous'],
'#options' => array(
COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'),
COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'),
COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'),
),
'#access' => user_access('post comments', backdrop_anonymous_user()),
);
if (config_get('system.core', 'user_pictures')) {
$form['comment']['comment_user_picture'] = array(
'#type' => 'checkbox',
'#title' => t('Display pictures for comment authors'),
'#default_value' => $node_type->settings['comment_user_picture'],
);
}
$form['comment']['comment_form_location'] = array(
'#type' => 'checkbox',
'#title' => t('Show reply form on the same page as comments'),
'#default_value' => $node_type->settings['comment_form_location'],
);
$form['comment']['comment_preview'] = array(
'#type' => 'radios',
'#title' => t('Preview comment'),
'#default_value' => $node_type->settings['comment_preview'],
'#options' => array(
BACKDROP_DISABLED => t('Disabled'),
BACKDROP_OPTIONAL => t('Optional'),
BACKDROP_REQUIRED => t('Required'),
),
);
$form['comment']['comment_close_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Automatically close comments on old content'),
'#default_value' => $node_type->settings['comment_close_enabled'],
);
$form['comment']['comment_close_days'] = array(
'#type' => 'number',
'#min' => 1,
'#step' => 1,
'#size' => 4,
'#maxlength' => 4,
'#states' => array(
'invisible' => array(
':input[name="comment_close_enabled"]' => array('checked' => FALSE),
),
),
'#field_prefix' => t('Close comments after'),
'#default_value' => $node_type->settings['comment_close_days'],
'#field_suffix' => t('days'),
);
$form['comment']['comment_title_options'] = array(
'#type' => 'radios',
'#title' => t('Comment titles'),
'#default_value' => $node_type->settings['comment_title_options'],
'#options' => array(
COMMENT_TITLE_CUSTOM => t('Visible, customizable'),
COMMENT_TITLE_AUTO => t('Visible, auto-generated'),
COMMENT_TITLE_HIDDEN => t('Hidden'),
),
);
$form['comment']['comment_title_options'][COMMENT_TITLE_CUSTOM]['#description'] = t('A title field is provided, to allow customizing comment titles.');
$form['comment']['comment_title_options'][COMMENT_TITLE_AUTO]['#description'] = t('Comment titles are automatically generated from the comment body.');
$form['comment']['comment_title_options'][COMMENT_TITLE_HIDDEN]['#description'] = t('Note: this option might not be supported by some themes.');
}
}