You are here

function comment_sort_created_form_node_type_form_alter in Comment sort by created 7

Implements hook_form_FORM_ID_alter().

Add comment configuration settings to the edit content type form.

File

./comment_sort_created.module, line 157
Sorts comments by creation date.

Code

function comment_sort_created_form_node_type_form_alter(&$form, $form_state) {

  // Whether to correct sort order.
  $form['comment']['comment_sort_created'] = array(
    '#title' => t('Sort comments by creation date?'),
    '#description' => t('Instead of sorting by comment id, this will sort the comments by the creation timestamp.'),
    '#type' => 'checkbox',
    '#default_value' => variable_get('comment_sort_created_' . $form['#node_type']->type, FALSE),
  );

  // Sort order.
  $form['comment']['comment_sort_created_order'] = array(
    '#title' => t('Sort order'),
    '#type' => 'select',
    '#states' => array(
      'visible' => array(
        ':input[name="comment_sort_created"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#options' => array(
      COMMENT_SORT_CREATED_OLDER_FIRST => t('Oldest first'),
      COMMENT_SORT_CREATED_NEWER_FIRST => t('Newest first'),
    ),
    '#default_value' => variable_get('comment_sort_created_order_' . $form['#node_type']->type, COMMENT_SORT_CREATED_OLDER_FIRST),
  );
  $form['#submit'][] = 'comment_sort_created_check_tables_in_sync';
}