You are here

function securelogin_form_alter in Secure Login 8

Same name and namespace in other branches
  1. 5 securelogin.module \securelogin_form_alter()
  2. 6 securelogin.module \securelogin_form_alter()
  3. 7 securelogin.module \securelogin_form_alter()

Implements hook_form_alter().

File

./securelogin.module, line 15
Secure login module.

Code

function securelogin_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Load secure login configuration.
  $conf = \Drupal::config('securelogin.settings');
  $other_forms = $conf
    ->get('other_forms');

  // Changing the form id to the base form allows us to match all node forms
  // since the form id will be 'node_form'.
  if (isset($form_state
    ->getBuildInfo()['base_form_id'])) {
    $form_id = $form_state
      ->getBuildInfo()['base_form_id'];
  }
  if ($conf
    ->get('all_forms')) {
    $form['#https'] = TRUE;
  }
  elseif ($conf
    ->get('form_' . $form_id)) {
    $form['#https'] = TRUE;
  }
  elseif (!empty($other_forms) && in_array($form_id, explode(' ', $other_forms))) {
    $form['#https'] = TRUE;
  }
  if (!empty($form['#https'])) {
    \Drupal::service('securelogin.manager')
      ->secureForm($form);
  }
}