function comment_perm_form_alter in Comment Permissions 7
Same name and namespace in other branches
- 5 comment_perm.module \comment_perm_form_alter()
- 6 comment_perm.module \comment_perm_form_alter()
- 7.2 comment_perm.module \comment_perm_form_alter()
Implementation of hook_form_alter().
File
- ./
comment_perm.module, line 121 - Module to control commenting permissions by role and by node type.
Code
function comment_perm_form_alter(&$form, $form_state, $form_id) {
#comment_node_merci_reservation_form
if ($form['#id'] == 'comment-form' and arg(0) == 'comment') {
$types = variable_get('comment_perm_node_types', array());
$form_id_types = array();
if (is_array($types)) {
foreach ($types as $type) {
if ($form_id == 'comment_node_' . $type . '_form') {
$nid = $form['nid']['#value'];
if (!comment_perm_access($nid)) {
// for comment reply pages, redirect back to the node
if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
drupal_set_message(_comment_perm_access_denied_message($nid), 'error');
drupal_goto('node/' . arg(2));
}
}
if (arg(0) == 'comment' && arg(2) == 'edit' && is_numeric(arg(1))) {
if (!comment_perm_edit_access($nid)) {
drupal_set_message(_comment_perm_access_denied_message($nid), 'error');
drupal_goto('node/' . $nid);
}
}
}
}
}
}
// Allow users to administer comment settings per content type.
if (!empty($form['#node_edit_form']) && isset($form['comment_settings'])) {
// Determine if user has access to administer comments.
if (comment_perm_administer_access($form['#node'])) {
$form['comment_settings']['#access'] = TRUE;
}
}
}