comment_form_alter
- Versions
- 4.7 – 5
comment_form_alter($form_id, &$form)- 6 – 7
comment_form_alter(&$form, $form_state, $form_id)
Implement hook_form_alter().
Code
modules/comment/comment.module, line 1015
<?php
function comment_form_alter(&$form, $form_state, $form_id) {
if (!empty($form['#node_edit_form'])) {
$node = $form['#node'];
$form['comment_settings'] = array(
'#type' => 'fieldset',
'#access' => user_access('administer comments'),
'#title' => t('Comment settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(drupal_get_path('module', 'comment') . '/comment-node-form.js'),
),
'#weight' => 30,
);
$comment_count = isset($node->nid) ? db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() : 0;
$comment_settings = ($node->comment == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment;
$form['comment_settings']['comment'] = array(
'#type' => 'radios',
'#parents' => array('comment'),
'#default_value' => $comment_settings,
'#options' => array(
COMMENT_NODE_OPEN => t('Open'),
COMMENT_NODE_CLOSED => t('Closed'),
COMMENT_NODE_HIDDEN => t('Hidden'),
),
COMMENT_NODE_OPEN => array(
'#type' => 'radio',
'#title' => t('Open'),
'#description' => t('Users with the "Post comments" permission can post comments.'),
'#return_value' => COMMENT_NODE_OPEN,
'#default_value' => $comment_settings,
'#id' => 'edit-comment-2',
'#parents' => array('comment'),
),
COMMENT_NODE_CLOSED => array(
'#type' => 'radio',
'#title' => t('Closed'),
'#description' => t('Users cannot post comments, but existing comments will be displayed.'),
'#return_value' => COMMENT_NODE_CLOSED,
'#default_value' => $comment_settings,
'#id' => 'edit-comment-1',
'#parents' => array('comment'),
),
COMMENT_NODE_HIDDEN => array(
'#type' => 'radio',
'#title' => t('Hidden'),
'#description' => t('Comments are hidden from view.'),
'#return_value' => COMMENT_NODE_HIDDEN,
'#default_value' => $comment_settings,
'#id' => 'edit-comment-0',
'#parents' => array('comment'),
),
);
// If the node doesn't have any comments, the "hidden" option makes no
// sense, so don't even bother presenting it to the user.
if (empty($comment_count)) {
unset($form['comment_settings']['comment']['#options'][COMMENT_NODE_HIDDEN]);
unset($form['comment_settings']['comment'][COMMENT_NODE_HIDDEN]);
$form['comment_settings']['comment'][COMMENT_NODE_CLOSED]['#description'] = t('Users cannot post comments.');
}
}
}
?>Login or register to post comments 