1 comment.theme.inc template_preprocess_comment(&$variables)

Preprocesses variables for comment.tpl.php.

See also

comment.tpl.php

File

core/modules/comment/comment.theme.inc, line 79
Theme functions for the Comment module.

Code

function template_preprocess_comment(&$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  $variables['bundle'] = $variables['elements']['#bundle'];
  $comment = $variables['elements']['#comment'];
  $node = $variables['elements']['#node'];
  $node_type = node_type_get_type($node->type);

  $variables['comment'] = $comment;
  $variables['node'] = $node;
  $variables['author'] = theme('username', array('account' => $comment));
  $variables['user_picture'] = '';
  $variables['created'] = format_date($comment->created);
  // Avoid calling format_date() twice on the same timestamp.
  if ($comment->changed == $comment->created) {
    $variables['changed'] = $variables['created'];
  }
  else {
    $variables['changed'] = format_date($comment->changed);
  }

  $variables['new'] = !empty($comment->new) ? t('new') : '';
  if ($node_type->settings['comment_user_picture']) {
    $variables['user_picture'] = theme('user_picture', array('account' => $comment));
  }
  $variables['signature'] = $comment->signature;

  $uri = $comment->uri();
  $uri['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark'));

  $variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
  $variables['permalink_path'] = $uri['path'] . "#" . $uri['options']['fragment'];
  $variables['title_display'] = $node_type->settings['comment_title_options'] != COMMENT_TITLE_HIDDEN;
  $variables['title'] = l($comment->subject, $uri['path'], $uri['options']);
  $variables['submitted'] = t('!datetime by !username', array('!datetime' => $variables['created'], '!username' => $variables['author']));

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

  // 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.
  // 'comment-published' class is not needed, it is either 'comment-preview' or
  // 'comment-unpublished'.
  if ($variables['status'] != 'comment-published') {
    $variables['classes'][] = $variables['status'];
  }
  if ($variables['new']) {
    $variables['classes'][] = 'comment-new';
  }
  if (!$comment->uid) {
    $variables['classes'][] = 'comment-by-anonymous';
  }
  else {
    if ($comment->uid == $variables['node']->uid) {
      $variables['classes'][] = 'comment-by-node-author';
    }
    if ($comment->uid == $variables['user']->uid) {
      $variables['classes'][] = 'comment-by-viewer';
    }
  }
  if ($node_type->settings['comment_title_options'] == COMMENT_TITLE_HIDDEN) {
    $variables['classes'][] = 'comment-title-hidden';
  }
  elseif ($node_type->settings['comment_title_options'] == COMMENT_TITLE_AUTO) {
    $variables['classes'][] = 'comment-title-auto';
  }
  else {
    $variables['classes'][] = 'comment-title-custom';
  }

  // Gather classes specific to the comment title.
  $variables['title_classes'][] = 'comment-title';
}