comment_preview

Versions
4.6
comment_preview($edit)
7
comment_preview($comment)

Generate a comment preview.

Code

modules/comment/comment.module, line 1917

<?php
function comment_preview($comment) {
  global $user;

  drupal_set_title(t('Preview comment'), PASS_THROUGH);

  $node = node_load($comment->nid);

  if (!form_get_errors()) {
    $comment->format = $comment->comment_format;

    // Attach the user and time information.
    if (!empty($comment->author)) {
      $account = user_load_by_name($comment->author);
    }
    elseif ($user->uid && !isset($comment->is_anonymous)) {
      $account = $user;
    }

    if (!empty($account)) {
      $comment->uid = $account->uid;
      $comment->name = check_plain($account->name);
    }
    elseif (empty($comment->name)) {
      $comment->name = variable_get('anonymous', t('Anonymous'));
    }

    $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME;
    $comment->changed = REQUEST_TIME;
    $comment->in_preview = TRUE;
    $comment_build = comment_build($comment, $node);
    $comment_build += array(
      '#weight' => -100,
      '#prefix' => '<div class="preview">',
      '#suffix' => '</div>',
    );

    $form['comment_preview'] = $comment_build;
  }

  if ($comment->pid) {
    $build = array();
    if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) {
      $parent_comment = $comments[$comment->pid];
      $build = comment_build($parent_comment, $node);
    }
  }
  else {
    $build = node_build($node);
  }

  $form['comment_output_below'] = $build;
  $form['comment_output_below']['#weight'] = 100;

  return $form;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.