You are here

function ajax_comments_preprocess_node in AJAX Comments 7

Implements hook_preprocess_node().

AJAXify "Add new comment" link when there is no default form.

File

./ajax_comments.module, line 105
AJAX comments module file.

Code

function ajax_comments_preprocess_node(&$variables) {
  $node = $variables['node'];
  $view_mode = $variables['view_mode'];
  if (!ajax_comments_node_type_active($node->type)) {
    return;
  }
  if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW) {
    return;
  }
  if (empty($node->comment) || $node->comment == COMMENT_NODE_CLOSED) {
    return;
  }
  drupal_add_library('system', 'drupal.ajax');
  drupal_add_library('system', 'drupal.form');
  drupal_add_js(drupal_get_path('module', 'ajax_comments') . '/ajax_comments.js', 'file');
  $variables['content']['links']['comment']['#links']['comment-add']['attributes']['class'][] = 'use-ajax-comments';
  $variables['content']['links']['comment']['#links']['comment-add']['attributes']['class'][] = 'ajax-comments-reply-' . $node->nid . '-0';
  $variables['content']['links']['comment']['#links']['comment-add']['fragment'] = NULL;
}