You are here

function protected_submissions_form_alter in Protected Submissions 8

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

Implements hook_form_alter().

File

./protected_submissions.module, line 57
Protected Submissions module.

Code

function protected_submissions_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
  $user = \Drupal::currentUser();

  // Exit early if current user has permission to bypass the validation process.
  if ($user
    ->hasPermission('bypass protected submissions validation') == FALSE) {

    // Validate webform, contact and node forms.
    if (strpos($form_id, 'user_') !== FALSE || strpos($form_id, 'node_') !== FALSE || strpos($form_id, 'comment_') !== FALSE || strpos($form_id, 'contact_message_') !== FALSE || strpos($form_id, 'webform_') !== FALSE) {
      $form['#validate'][] = '_protected_submissions_validate';
    }
  }
}