function comment_preview

cis7 comment.module comment_preview($comment)
cle7 comment.module comment_preview($comment)
elmsmedia7 comment.module comment_preview($comment)
icor7 comment.module comment_preview($comment)
meedjum_blog7 comment.module comment_preview($comment)
mooc7 comment.module comment_preview($comment)

Generate a comment preview.

1 call to comment_preview()
comment_form_build_preview in modules/comment/comment.module
Build a preview from submitted form values.
6 string references to 'comment_preview'
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
comment_form_build_preview in modules/comment/comment.module
Build a preview from submitted form values.
comment_form_node_type_form_alter in modules/comment/comment.module
Implements hook_form_FORM_ID_alter().
comment_node_type_delete in modules/comment/comment.module
Implements hook_node_type_delete().
comment_theme in modules/comment/comment.module
Implements hook_theme().

... See full list

File

modules/comment/comment.module, line 2062
Enables users to comment on published content.

Code

function comment_preview($comment) {
  global $user;

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

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

  if (!form_get_errors()) {
    $comment_body = field_get_items('comment', $comment, 'comment_body');
    $comment->format = $comment_body[0]['format'];
    // Attach the user and time information.
    if (!empty($comment->name)) {
      $account = user_load_by_name($comment->name);
    }
    elseif ($user->uid && empty($comment->is_anonymous)) {
      $account = $user;
    }

    if (!empty($account->uid)) {
      $comment->uid = $account->uid;
      $comment->name = check_plain($account->name);
      $comment->signature = $account->signature;
      $comment->signature_format = $account->signature_format;
      $comment->picture = $account->picture;
    }
    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_view($comment, $node);
    $comment_build['#weight'] = -100;

    $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_view($parent_comment, $node);
    }
  }
  else {
    $build = node_view($node);
  }

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

  return $form;
}