Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.700 diff -u -p -r1.700 comment.module --- modules/comment/comment.module 17 Mar 2009 12:41:54 -0000 1.700 +++ modules/comment/comment.module 17 Mar 2009 17:28:32 -0000 @@ -500,6 +500,8 @@ function comment_node_view($node, $tease /** * Implementation of hook_form_FORM_ID_alter(). + * + * @see comment_process_comment_options() */ function comment_form_node_type_form_alter(&$form, $form_state) { if (isset($form['identity']['type'])) { @@ -513,8 +515,13 @@ function comment_form_node_type_form_alt '#type' => 'radios', '#title' => t('Default comment setting'), '#default_value' => variable_get('comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN), - '#options' => array(t('Hidden'), t('Closed'), t('Open')), + '#options' => array( + COMMENT_NODE_OPEN => t('Open'), + COMMENT_NODE_CLOSED => t('Closed'), + COMMENT_NODE_HIDDEN => t('Hidden'), + ), '#description' => t('Users with the administer comments permission will be able to override this setting.'), + '#process' => array('form_process_radios', 'comment_process_comment_options'), ); $form['comment']['comment_default_mode'] = array( '#type' => 'radios', @@ -570,6 +577,8 @@ function comment_form_node_type_form_alt /** * Implementation of hook_form_alter(). + * + * @see comment_process_comment_options() */ function comment_form_alter(&$form, $form_state, $form_id) { if (!empty($form['#node_edit_form'])) { @@ -593,45 +602,34 @@ function comment_form_alter(&$form, $for COMMENT_NODE_CLOSED => t('Closed'), COMMENT_NODE_HIDDEN => t('Hidden'), ), - COMMENT_NODE_OPEN => array( - '#type' => 'radio', - '#title' => t('Open'), - '#description' => theme('indentation') . t("Users with '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' => theme('indentation') . 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' => theme('indentation') . t('Comments are hidden from view.'), - '#return_value' => COMMENT_NODE_HIDDEN, - '#default_value' => $comment_settings, - '#id' => 'edit-comment-0', - '#parents' => array('comment'), - ), + '#process' => array('form_process_radios', 'comment_process_comment_options'), + '#comment_count' => $comment_count, ); - // 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'] = theme('indentation') . t('Users cannot post comments.'); - } } } /** + * Form element process callback; Adds descriptions to the comment option radios. + * + * @see comment_form_alter() + * @see comment_form_node_type_form_alter() + */ +function comment_process_comment_options($element) { + $element[COMMENT_NODE_OPEN]['#description'] = theme('indentation') . t("Users with 'post comments' permission can post comments."); + $element[COMMENT_NODE_CLOSED]['#description'] = theme('indentation') . t('Users cannot post comments, but existing comments will be displayed.'); + $element[COMMENT_NODE_HIDDEN]['#description'] = theme('indentation') . t('Comments are hidden from view.'); + + // 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($element['#comment_count'])) { + $element[COMMENT_NODE_HIDDEN]['#access'] = FALSE; + $element[COMMENT_NODE_CLOSED]['#description'] = theme('indentation') . t('Users cannot post comments.'); + } + + return $element; +} + +/** * Implementation of hook_node_load(). */ function comment_node_load($nodes, $types) {