ajax_comments_handler_field_ajax_add_comment.inc in AJAX Comments 7
File
views/ajax_comments_handler_field_ajax_add_comment.inc
View source
<?php
class ajax_comments_handler_field_ajax_add_comment extends views_handler_field_comment_node_link {
var $output;
function option_definition() {
$options = parent::option_definition();
$options['text'] = array(
'default' => '',
'translatable' => TRUE,
);
$options['submit_action'] = array(
'default' => 1,
);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
$actions = array(
1 => t('Show message'),
2 => t('Show link'),
);
$form['submit_action'] = array(
'#type' => 'select',
'#title' => t('After submit action'),
'#description' => t('Select the after comment submited action.'),
'#options' => $actions,
'#default_value' => $this->options['submit_action'],
);
parent::options_form($form, $form_state);
$form['alter']['path'] = array(
'#access' => FALSE,
);
$form['alter']['external'] = array(
'#access' => FALSE,
);
}
function pre_render(&$values) {
parent::pre_render($values);
drupal_add_js(drupal_get_path('module', 'ajax_comments') . '/ajax_comments.js');
drupal_add_library('system', 'drupal.ajax');
}
function render($values) {
if (user_access('post comments') && ($node = $this
->get_value($values))) {
$result = '<div class="comment-wrapper views-comment-wrapper-nid-' . $node->nid . '">';
$result .= '<p class="views-comment-result-nid-' . $node->nid . '" style="display: none;">' . t('Your comment has been posted.') . '</p>';
$result .= '<div class="ajax-comment-wrapper ajax-comment-dummy-comment"></div>';
$options = array(
'attributes' => array(
'class' => array(
'use-ajax-comments',
'ajax-comments-reply-' . $node->nid . '-0',
),
),
);
$path = 'comment/reply/' . $node->nid . '/0/' . $this->options['submit_action'];
$text = !empty($this->options['text']) ? $this->options['text'] : t('Add new comment');
$result .= l($text, $path, $options) . '</div>';
return $result;
}
}
}