Generates a comment preview.
Drupal\comment\Comment $comment:
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;
}