template_preprocess_comment

Versions
6 – 7
template_preprocess_comment(&$variables)

Process variables for comment.tpl.php.

See also

comment.tpl.php

Code

drupal/modules/comment/comment.module, line 2202

<?php
function template_preprocess_comment(&$variables) {
  $comment = $variables['elements']['#comment'];
  $node = $variables['elements']['#node'];
  $variables['comment']   = $comment;
  $variables['node']      = $node;
  $variables['author']    = theme('username', array('account' => $comment));
  $variables['created']   = format_date($comment->created);
  $variables['changed']   = format_date($comment->changed);

  $variables['new']       = !empty($comment->new) ? t('new') : '';
  $variables['picture']   = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';
  $variables['signature'] = $comment->signature;

  $uri = entity_uri('comment', $comment);
  $variables['title']     = l($comment->subject, $uri['path'], $uri['options']);
  $variables['permalink'] = l('#', $uri['path'], $uri['options']);

  // Preprocess fields.
  field_attach_preprocess('comment', $comment, $variables['elements'], $variables);

  $variables['theme_hook_suggestions'][] = 'comment__' . $variables['node']->type;

  // Helpful $content variable for templates.
  foreach (element_children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }

  // Set status to a string representation of comment->status.
  if (isset($comment->in_preview)) {
    $variables['status']  = 'comment-preview';
  }
  else {
    $variables['status']  = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';
  }
  // Gather comment classes.
  if ($comment->uid === 0) {
    $variables['classes_array'][] = 'comment-by-anonymous';
  }
  else {
    // Published class is not needed. It is either 'comment-preview' or 'comment-unpublished'.
    if ($variables['status'] != 'comment-published') {
      $variables['classes_array'][] = $variables['status'];
    }
    if ($comment->uid === $variables['node']->uid) {
      $variables['classes_array'][] = 'comment-by-node-author';
    }
    if ($comment->uid === $variables['user']->uid) {
      $variables['classes_array'][] = 'comment-by-viewer';
    }
    if ($variables['new']) {
      $variables['classes_array'][] = 'comment-new';
    }
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.