You are here

function comment_alter_comment_view in Comment Alter 7

Same name and namespace in other branches
  1. 8 comment_alter.module \comment_alter_comment_view()

Implements hook_comment_view().

See also

diff_diffs_show()

File

./comment_alter.module, line 510
Provides UI to alter nodes' parameters from comment forms.

Code

function comment_alter_comment_view($comment, $view_mode, $langcode) {

  // Strip 'comment_node_' to get the node type machine name.
  $type = substr($comment->node_type, 13);
  if ($view_mode == 'full' && isset($comment->comment_alter) && user_access('view comment alterations in ' . $type)) {
    $comment->content['comment_alter'] = array(
      '#theme' => 'comment_alter_diff',
      '#changed_fields' => comment_alter_get_changed_fields($comment, $langcode),
      '#comment' => $comment,
      '#langcode' => $langcode,
    );
  }

  // Add the link if needed AND current user has access to it.
  if (isset($comment->comment_alter) && isset($comment->comment_alter['new_vid'])) {
    $path = 'node/' . $comment->nid . '/revisions/view/' . $comment->comment_alter['old_vid'] . '/' . $comment->comment_alter['new_vid'];
    if (variable_get('comment_alter_diff_link_' . $type, 0) && drupal_valid_path($path)) {
      $comment->content['links']['comment']['#links']['comment-alter'] = array(
        'title' => t('diff'),
        'href' => $path,
        'html' => TRUE,
      );
    }
  }
}