You are here

function protected_submissions_form_alter in Protected Submissions 7

Same name and namespace in other branches
  1. 8 protected_submissions.module \protected_submissions_form_alter()

Implements hook_form_alter().

File

./protected_submissions.module, line 718
Blocks submissions from anonymous users that contain pre-defined strings.

Code

function protected_submissions_form_alter(&$form, &$form_state, $form_id) {
  global $user;

  // Exit early if current user has bypass permission.
  // Not using user_access(), because user #1 has all privileges per
  // https://api.drupal.org/api/drupal/modules!user!user.module/function/user_access/7.x
  $found_key = array_search(TRUE, array_column(user_role_permissions($user->roles), 'bypass protected_submissions'));
  if ($found_key !== FALSE) {
    return;
  }
  if (strpos($form_id, '_node_form') !== FALSE || strpos($form_id, 'comment_node_') !== FALSE || strpos($form_id, 'contact_') !== FALSE || strpos($form_id, 'webform_') !== FALSE) {
    $form['#validate'][] = '_protected_submissions_validate';
  }
}