diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 1b1dd79..9527956 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1177,6 +1177,20 @@ function comment_view_multiple($comments, Node $node, $view_mode = 'full', $weig * Implements hook_form_FORM_ID_alter(). */ function comment_form_node_type_form_alter(&$form, $form_state) { + + if (($form['#form_id'] == 'node_type_form') && (config('comment.settings')->get($form['#node_type']->type . '.comment_saved_' . $form['#node_type']->type) == '0')) { + // Save the default values to config if config is empty. + config('comment.settings')->set($form['#node_type']->type . '.comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN); + config('comment.settings')->set($form['#node_type']->type . '.comment_default_mode_' . $form['#node_type']->type, COMMENT_MODE_THREADED); + config('comment.settings')->set($form['#node_type']->type . '.comment_default_per_page_' . $form['#node_type']->type, 50); + config('comment.settings')->set($form['#node_type']->type . '.comment_anonymous_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT); + config('comment.settings')->set($form['#node_type']->type . '.comment_subject_field_' . $form['#node_type']->type, 1); + config('comment.settings')->set($form['#node_type']->type . '.comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW); + config('comment.settings')->set($form['#node_type']->type . '.comment_preview_' . $form['#node_type']->type, DRUPAL_OPTIONAL); + config('comment.settings')->set($form['#node_type']->type . '.comment_saved_' . $form['#node_type']->type, 1); + config('comment.settings')->save(); + } + if (isset($form['type'])) { $form['comment'] = array( '#type' => 'fieldset', @@ -1191,13 +1205,14 @@ function comment_form_node_type_form_alter(&$form, $form_state) { 'library' => array('comment', 'drupal.comment'), ), ); + // Unlike coment_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'] = array( '#type' => 'select', '#title' => t('Default comment setting for new content'), - '#default_value' => variable_get('comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_' . $form['#node_type']->type), '#options' => array( COMMENT_NODE_OPEN => t('Open'), COMMENT_NODE_CLOSED => t('Closed'), @@ -1207,19 +1222,19 @@ function comment_form_node_type_form_alter(&$form, $form_state) { $form['comment']['comment_default_mode'] = array( '#type' => 'checkbox', '#title' => t('Threading'), - '#default_value' => variable_get('comment_default_mode_' . $form['#node_type']->type, COMMENT_MODE_THREADED), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_default_mode_' . $form['#node_type']->type), '#description' => t('Show comment replies in a threaded list.'), ); $form['comment']['comment_default_per_page'] = array( '#type' => 'select', '#title' => t('Comments per page'), - '#default_value' => variable_get('comment_default_per_page_' . $form['#node_type']->type, 50), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_default_per_page_' . $form['#node_type']->type), '#options' => _comment_per_page(), ); $form['comment']['comment_anonymous'] = array( '#type' => 'select', '#title' => t('Anonymous commenting'), - '#default_value' => variable_get('comment_anonymous_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_anonymous_' . $form['#node_type']->type), '#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'), @@ -1230,27 +1245,46 @@ function comment_form_node_type_form_alter(&$form, $form_state) { $form['comment']['comment_subject_field'] = array( '#type' => 'checkbox', '#title' => t('Allow comment title'), - '#default_value' => variable_get('comment_subject_field_' . $form['#node_type']->type, 1), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_subject_field_' . $form['#node_type']->type), ); $form['comment']['comment_form_location'] = array( '#type' => 'checkbox', '#title' => t('Show reply form on the same page as comments'), - '#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_form_location_' . $form['#node_type']->type), ); $form['comment']['comment_preview'] = array( '#type' => 'radios', '#title' => t('Preview comment'), - '#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, DRUPAL_OPTIONAL), + '#default_value' => config('comment.settings')->get($form['#node_type']->type . '.comment_preview_' . $form['#node_type']->type), '#options' => array( DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), DRUPAL_REQUIRED => t('Required'), ), ); + $form['#submit'][] = 'comment_submit_config'; } } /** + * Implements callback submit to store conf values + * for the node type form(). + */ +function comment_submit_config($form, &$form_state) { + $config = config('comment.settings'); + $config->set($form['#node_type']->type . '.comment_' . $form['#node_type']->type, $form_state['values']['comment']); + $config->set($form['#node_type']->type . '.comment_default_mode_' . $form['#node_type']->type, $form_state['values']['comment_default_mode']); + $config->set($form['#node_type']->type . '.comment_default_per_page_' . $form['#node_type']->type, $form_state['values']['comment_default_per_page']); + $config->set($form['#node_type']->type . '.comment_anonymous_' . $form['#node_type']->type, $form_state['values']['comment_anonymous']); + $config->set($form['#node_type']->type . '.comment_subject_field_' . $form['#node_type']->type, $form_state['values']['comment_subject_field']); + $config->set($form['#node_type']->type . '.comment_form_location_' . $form['#node_type']->type, $form_state['values']['comment_form_location']); + $config->set($form['#node_type']->type . '.comment_preview_' . $form['#node_type']->type, $form_state['values']['comment_preview']); + $config->set($form['#node_type']->type . '.comment_saved_' . $form['#node_type']->type, 1); + $config->save(); + watchdog('comment', 'CMI configuration variables updated for node type %type', array('%type' => $form['#node_type']->type)); +} + +/** * Implements hook_form_BASE_FORM_ID_alter(). */ function comment_form_node_form_alter(&$form, $form_state) { @@ -1300,6 +1334,7 @@ function comment_form_node_form_alter(&$form, $form_state) { // Also adjust the description of the "closed" option. $form['comment_settings']['comment'][COMMENT_NODE_CLOSED]['#description'] = t('Users cannot post comments.'); } + $form['#submit'][] = 'comment_node_submit_config'; } /** diff --git a/core/modules/comment/config/comment.settings.yml b/core/modules/comment/config/comment.settings.yml new file mode 100755 index 0000000..2b1129e --- /dev/null +++ b/core/modules/comment/config/comment.settings.yml @@ -0,0 +1,18 @@ +article: + comment_article: '2' + comment_default_mode_article: '1' + comment_default_per_page_article: '50' + comment_anonymous_article: '0' + comment_subject_field_article: '1' + comment_form_location_article: '1' + comment_preview_article: '0' + comment_saved_article: '0' +page: + comment_page: '2' + comment_default_mode_page: '1' + comment_default_per_page_page: '50' + comment_anonymous_page: '0' + comment_subject_field_page: '1' + comment_form_location_page: '1' + comment_preview_page: '0' + comment_saved_page: '0'