You are here

function quote_form_alter in Quote 7

Same name and namespace in other branches
  1. 8.2 quote.module \quote_form_alter()
  2. 5 quote.module \quote_form_alter()
  3. 6.2 quote.module \quote_form_alter()
  4. 6 quote.module \quote_form_alter()
  5. 7.2 quote.module \quote_form_alter()

Implements hook_form_alter().

File

./quote.module, line 120
The quote module provides a filter and appropriate links that allow users to quote nodes and other comments in their own comments.

Code

function quote_form_alter(&$form, &$form_state, $form_id) {

  // The explanation for the $_POST check is further below.
  if ($form['#id'] == 'comment-form' && (isset($_POST['quote']) || isset($_GET['quote']) && $_GET['quote'])) {
    $nid = arg(2);
    $cid = arg(3);
    if ($cid || _quote_variable_get('node_link_display')) {
      extract(_quote_get_quoted_data($nid, $cid));
      $quote = "[quote={$author}]" . trim($content) . "[/quote]\n";
      $language = $form['comment_body']['#language'];
      if (array_key_exists('#default_value', $form['comment_body'][$language][0])) {

        // Add quoted text and preserve existing content (signature etc.).
        $form['comment_body'][$language][0]['#default_value'] = $quote . $form['comment_body'][$language][0]['#default_value'];
      }
      else {
        $form['comment_body'][$language][0]['value']['#default_value'] = $quote . $form['comment_body'][$language][0]['value']['#default_value'];
      }

      // Set the text format to the format selected in the quote configuration
      // page.
      $form['comment_body'][$language][0]['#format'] = _quote_variable_get('format');

      // The Form API, by default, drops name-value pairs from the form's action
      // URL (besides ?q=). Manually adding it back in as a hidden element.
      $form['quote'] = array(
        '#type' => 'hidden',
        '#value' => 1,
      );
    }
  }
}