function comment_preview

Generates a comment preview.

Parameters

Drupal\comment\Comment $comment:

1 call to comment_preview()
CommentFormController::preview in drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php
Form submission handler for the 'preview' action.
2 string references to 'comment_preview'
CommentTestBase::setCommentPreview in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
Sets the value governing the previewing mode for the comment form.
comment_node_type_delete in drupal/core/modules/comment/comment.module
Implements hook_node_type_delete().

File

drupal/core/modules/comment/comment.module, line 1582
Enables users to comment on published content.

Code

function comment_preview(Comment $comment) {
  global $user;
  $preview_build = array();
  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;
    }
    elseif (empty($comment->name)) {
      $comment->name = config('user.settings')
        ->get('anonymous');
    }
    $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME;
    $comment->changed = REQUEST_TIME;
    $comment->in_preview = TRUE;
    $comment_build = comment_view($comment);
    $comment_build['#weight'] = -100;
    $preview_build['comment_preview'] = $comment_build;
  }
  if ($comment->pid) {
    $build = array();
    $comment = comment_load($comment->pid);
    if ($comment && $comment->status == COMMENT_PUBLISHED) {
      $build = comment_view($comment);
    }
  }
  else {
    $build = node_view(node_load($comment->nid));
  }
  $preview_build['comment_output_below'] = $build;
  $preview_build['comment_output_below']['#weight'] = 100;
  return $preview_build;
}