function comment_perm_form_alter in Comment Permissions 5
Same name and namespace in other branches
- 6 comment_perm.module \comment_perm_form_alter()
- 7.2 comment_perm.module \comment_perm_form_alter()
- 7 comment_perm.module \comment_perm_form_alter()
Implementation of hook_form_alter().
File
- ./
comment_perm.module, line 111
Code
function comment_perm_form_alter($form_id, &$form) {
if ($form_id == 'comment_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(), 'error');
drupal_goto('node/' . arg(2));
}
else {
// for inline comment forms, such remove their fields so nothing will show
unset($form['comment_filter']);
foreach ($form as $key => $item) {
if ($type = $item['#type']) {
switch ($type) {
case 'value':
case 'hidden':
// keep these
break;
default:
// remove all others
unset($form[$key]);
break;
}
}
}
// display a message to users who can't post comments
$form['text'] = array(
'#value' => '<p id="comment-perm-access-denied">' . _comment_perm_access_denied_message() . '</p>',
);
}
}
}
}