You are here

function discussthis_create_discussion_form in Discuss This! 7

Same name and namespace in other branches
  1. 7.2 discussthis.discussion.inc \discussthis_create_discussion_form()

Create a discussion comment form.

Parameters

$form_state The current state of the form:

$nid The node that is being discussed:

Return value

The form in HTML

1 string reference to 'discussthis_create_discussion_form'
discussthis_menu in ./discussthis.module
Implements hook_menu().

File

./discussthis.discussion.inc, line 17
Functions to create/link/delete discussions.

Code

function discussthis_create_discussion_form($form, &$form_state, $nid) {

  // the user usually enters this function because the topic does not
  // exist yet, this form asks for the comment with our own discussthis
  // form (i.e. avoid creating a new forum node until the person posts
  // his/her comment out)
  //
  // IMPORTANT: we do NOT check whether the topic already exists because
  // it might when the person clicks on Preview. Please, see the submit
  // function for more information in that regard. Just don't add a test
  // for the topic ID in this function...
  $title = variable_get('discussthis_new_post_title', '');
  if ($title) {
    drupal_set_title($title);
  }
  global $user;
  $op = empty($form_state['post']['op']) ? '' : $form_state['post']['op'];
  $is_ready = $op == t('Preview') || $op == t('Save');
  if ($is_ready) {
    $comment = $user;
    $comment->comment = check_markup($form_state['post']['comment'], $form_state['post']['format'], $langcode = '', FALSE);
    $comment->timestamp = REQUEST_TIME;
    $comment->new = FALSE;

    // this is not displayed in a very good way, in general
    $comment->preview = TRUE;
    $comment->subject = $form_state['post']['subject'];
    $node = array(
      'type' => 'forum',
    );
    $node = (object) $node;
    $form['preview_comment'] = array(
      '#title' => t('Preview'),
      '#value' => theme('comment', $comment, $node),
    );
  }
  $comment_anonymous_forum = variable_get('comment_anonymous_forum', COMMENT_ANONYMOUS_MAYNOT_CONTACT);
  if (!$user->uid && $comment_anonymous_forum != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
    drupal_add_js(drupal_get_path('module', 'comment') . '/comment.js');
  }
  if ($user->uid) {
    $form['_author'] = array(
      '#type' => 'item',
      '#title' => t('Your name'),
      '#value' => theme('username', array(
        'account' => $user,
      )),
    );
    $form['author'] = array(
      '#type' => 'value',
      '#value' => $user->name,
    );
  }
  elseif ($comment_anonymous_forum == COMMENT_ANONYMOUS_MAY_CONTACT) {
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Your name'),
      '#maxlength' => 60,
      '#size' => 30,
      '#default_value' => variable_get('anonymous', t('Anonymous')),
    );
    $form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail'),
      '#maxlength' => 64,
      '#size' => 30,
      '#description' => t('The content of this field is kept private and will not be shown publicly.'),
    );
    $form['homepage'] = array(
      '#type' => 'textfield',
      '#title' => t('Homepage'),
      '#maxlength' => 255,
      '#size' => 30,
    );
  }
  elseif ($comment_anonymous_forum == COMMENT_ANONYMOUS_MUST_CONTACT) {
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Your name'),
      '#maxlength' => 60,
      '#size' => 30,
      '#default_value' => variable_get('anonymous', t('Anonymous')),
      '#required' => TRUE,
    );
    $form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail'),
      '#maxlength' => 64,
      '#size' => 30,
      '#description' => t('The content of this field is kept private and will not be shown publicly.'),
      '#required' => TRUE,
    );
    $form['homepage'] = array(
      '#type' => 'textfield',
      '#title' => t('Homepage'),
      '#maxlength' => 255,
      '#size' => 30,
    );
  }
  if (variable_get('comment_subject_field_forum', 1) == 1) {
    $form['subject'] = array(
      '#type' => 'textfield',
      '#title' => t('Subject'),
      '#maxlength' => 64,
    );
  }
  $form['comment_filter']['comment'] = array(
    '#type' => 'text_format',
    '#base_type' => 'textarea',
    '#title' => t('Comment'),
    '#rows' => 15,
    '#required' => TRUE,
    '#format' => isset($edit['format']) ? $edit['format'] : NULL,
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $user->uid,
  );
  $form['discussthis_nid'] = array(
    '#type' => 'value',
    '#value' => $nid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 19,
  );
  $form['#submit'][] = 'discussthis_create_discussion_form_submit';
  $form['preview'] = array(
    '#type' => 'button',
    '#value' => t('Preview'),
    '#weight' => 20,
  );
  return $form;
}