flatcomments.module in Flatcomments 6.2
Same filename and directory in other branches
Make comments replies to the node, regardless of the reply link used.
File
flatcomments.moduleView source
<?php
/**
* @file
* Make comments replies to the node, regardless of the reply link used.
*/
/**
* Implementation of hook_form_alter().
*/
function flatcomments_form_alter(&$form, $form_state, $form_id) {
switch ($form['#id']) {
case 'comment-form':
case 'panels-comment-form':
array_unshift($form['#submit'], 'flatcomments_comment_form_submit');
break;
case 'node-type-form':
// Add note about flatcomments to comment display description.
$form['comment']['comment_default_mode']['#description'] .= t(' <strong>Flatcomments enabled:</strong> flat list options will force replies to be to the main post.');
// Add option to default display mode.
$form['comment']['comment_default_mode']['#options'][5] = t('Orderable flat list - expanded');
// Add submit handler to handle additional display mode.
array_unshift($form['#submit'], 'flatcomments_node_type_form_submit');
// If display mode is 2 and our variable is 5 then set default value to 5.
$display_mode = $form['comment']['comment_default_mode']['#default_value'];
$node_type = $form['#node_type']->type;
$orderable = variable_get('flatcomments_default_mode_' . $node_type, 0);
if ($display_mode == 4 && $orderable == 5 && !$form_state['submitted']) {
$form['comment']['comment_default_mode']['#default_value'] = 5;
}
// Add option to remove reply link from comments.
$form['comment']['flatcomments_remove_reply_link'] = array(
'#type' => 'checkboxes',
'#title' => t('Links'),
'#default_value' => variable_get('flatcomments_remove_reply_link_' . $node_type, array()),
'#options' => array(
'reply' => t('Do not show a reply link on comments'),
),
);
break;
}
}
/**
* Sets comment pid to null prior to comment save.
*
* @see flatcomments_form_alter()
*/
function flatcomments_comment_form_submit($form, &$form_state) {
$node = node_load($form_state['values']['nid']);
$display_mode = (int) variable_get('comment_default_mode_' . $node->type, 0);
$orderable = (int) variable_get('flatcomments_default_mode_' . $node->type, 0);
// Only alter new comments.
if ((in_array($display_mode, array(
1,
2,
)) || $orderable === 5) && !$form_state['values']['cid']) {
// Setting pid to NULL makes the comment a reply to the node.
$form_state['values']['pid'] = NULL;
}
}
/**
* Handles comment display mode save for our custom option.
*
* @see flatcomments_form_alter()
*/
function flatcomments_node_type_form_submit($form, &$form_state) {
// Change display mode 5 to 2 to have comments display correctly.
// Then save mode 5 in our variable for flatcomments use.
$node_type = trim($form_state['values']['type']);
if ($form_state['values']['comment_default_mode'] == 5) {
$form_state['values']['comment_default_mode'] = 4;
variable_set('flatcomments_default_mode_' . $node_type, 5);
}
else {
variable_set('flatcomments_default_mode_' . $node_type, 0);
}
}
/**
* Implementation of hook_node_type().
*/
function flatcomments_node_type($op, $info) {
switch ($op) {
case 'delete':
variable_del('flatcomments_default_mode_' . $info->type);
break;
}
}
/**
* Implementation of hook_link_alter().
*/
function flatcomments_link_alter(&$links, $node, $comment = NULL) {
if (isset($links['comment_reply'])) {
$remove = variable_get('flatcomments_remove_reply_link_' . $node->type, array());
if (!empty($remove)) {
// Remove the reply link.
unset($links['comment_reply']);
}
}
}
Functions
Name | Description |
---|---|
flatcomments_comment_form_submit | Sets comment pid to null prior to comment save. |
flatcomments_form_alter | Implementation of hook_form_alter(). |
flatcomments_link_alter | Implementation of hook_link_alter(). |
flatcomments_node_type | Implementation of hook_node_type(). |
flatcomments_node_type_form_submit | Handles comment display mode save for our custom option. |