You are here

function flatcomments_form_alter in Flatcomments 6.2

Same name and namespace in other branches
  1. 5 flatcomments.module \flatcomments_form_alter()
  2. 6 flatcomments.module \flatcomments_form_alter()

Implementation of hook_form_alter().

File

./flatcomments.module, line 11
Make comments replies to the node, regardless of the reply link used.

Code

function flatcomments_form_alter(&$form, $form_state, $form_id) {
  switch ($form['#id']) {
    case 'comment-form':
    case 'panels-comment-form':
      array_unshift($form['#submit'], 'flatcomments_comment_form_submit');
      break;
    case 'node-type-form':

      // Add note about flatcomments to comment display description.
      $form['comment']['comment_default_mode']['#description'] .= t(' <strong>Flatcomments enabled:</strong> flat list options will force replies to be to the main post.');

      // Add option to default display mode.
      $form['comment']['comment_default_mode']['#options'][5] = t('Orderable flat list - expanded');

      // Add submit handler to handle additional display mode.
      array_unshift($form['#submit'], 'flatcomments_node_type_form_submit');

      // If display mode is 2 and our variable is 5 then set default value to 5.
      $display_mode = $form['comment']['comment_default_mode']['#default_value'];
      $node_type = $form['#node_type']->type;
      $orderable = variable_get('flatcomments_default_mode_' . $node_type, 0);
      if ($display_mode == 4 && $orderable == 5 && !$form_state['submitted']) {
        $form['comment']['comment_default_mode']['#default_value'] = 5;
      }

      // Add option to remove reply link from comments.
      $form['comment']['flatcomments_remove_reply_link'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Links'),
        '#default_value' => variable_get('flatcomments_remove_reply_link_' . $node_type, array()),
        '#options' => array(
          'reply' => t('Do not show a reply link on comments'),
        ),
      );
      break;
  }
}