1.20.x comment.module | comment_preview($comment) |
Generates a comment preview.
See also
File
- modules/
comment/ comment.module, line 2037 - Enables users to comment on published content.
Code
function comment_preview($comment) {
global $user;
backdrop_set_title(t('Preview comment'), PASS_THROUGH);
$node = node_load($comment->nid);
if (!form_get_errors()) {
// Empty comments and plain text comments do not have a format.
if (isset($comment->comment_body[LANGUAGE_NONE][0]['format'])) {
$comment->format = $comment->comment_body[LANGUAGE_NONE][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 = config_get('system.core', '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;
}