function ajax_comments_form_comment_form_alter in AJAX Comments 6
Same name and namespace in other branches
- 8 ajax_comments.module \ajax_comments_form_comment_form_alter()
- 7 ajax_comments.module \ajax_comments_form_comment_form_alter()
Implementation of hook_form_FORM_ID_alter().
File
- ./
ajax_comments.module, line 112 - Implements AJAX handling for Drupal comment forms.
Code
function ajax_comments_form_comment_form_alter(&$form, $form_state) {
if ($form['nid']['#value']) {
$node = node_load($form['nid']['#value']);
}
else {
$node = menu_get_object();
if ((!isset($node) || !$node->nid) && arg(0) == 'ajax_comments') {
$node = node_load(arg(2));
}
}
$allowed_node_types = variable_get('ajax_comments_node_types', array());
$all_allowed = TRUE;
foreach ($allowed_node_types as $type) {
if ($type) {
$all_allowed = FALSE;
break;
}
}
if ($all_allowed || isset($allowed_node_types[$node->type]) && $allowed_node_types[$node->type]) {
if (arg(1) != 'edit' && arg(1) != 'reply' && arg(2) != 'edit' && arg(2) != 'reply') {
$form['#prefix'] = '<div id="comment-preview"></div>';
// Overriding PID param so it will appear on the form.
$form['pid']['#type'] = 'hidden';
$form['pid']['#default_value'] = $form['pid']['#value'];
unset($form['pid']['#value']);
// Node id for rebuilding form if needed
$form['nid'] = array(
'#type' => 'hidden',
'#default_value' => $node->nid,
);
// We should set specific ID to let ahah wrapper know what to wrap on ajax
// loaded comment-form even if we have many submit buttons on the page.
$form['preview']['#id'] = "ajax-comments-preview";
$form['preview']['#ahah'] = array(
'path' => 'ajax_comments/js',
'wrapper' => 'comment-preview',
'event' => 'click',
'method' => 'append',
'effect' => 'ajaxCommentsPreview',
'progress' => array(
'type' => '1bar',
'message' => t('Please wait...'),
),
);
$form['submit']['#id'] = "ajax-comments-submit";
$form['submit']['#submit'] = array(
'ajax_comments_submit',
);
$form['submit']['#ahah'] = array(
'path' => 'ajax_comments/js',
'wrapper' => 'comment-form-content',
'event' => 'click',
'method' => 'before',
'effect' => 'ajaxCommentsSubmit',
'progress' => array(
'type' => '1bar',
'message' => t('Please wait...'),
),
);
}
}
}