You are here

function username_check_form_user_register_form_alter in Username originality AJAX check 8

Same name and namespace in other branches
  1. 7 username_check.module \username_check_form_user_register_form_alter()

@file Checks user name availability on registration page.

File

./username_check.module, line 8
Checks user name availability on registration page.

Code

function username_check_form_user_register_form_alter(&$form) {
  global $base_url;
  $module_path = drupal_get_path('module', 'username_check');
  $config = \Drupal::config('username_check.settings');
  $mode = $config
    ->get('username_check_mode');
  $mailmode = $config
    ->get('username_check_mail_mode', 'auto');
  $delay = $config
    ->get('username_check_delay');
  if ($mode != 'off') {
    $form['#attached']['library'] = array(
      'username_check/username_check',
    );
    $form['#attached']['drupalSettings']['usernameCheck']['ajaxUrl'] = $base_url . '/username_check/isunique';
    $form['#attached']['drupalSettings']['usernameCheck']['delay'] = $delay;
    $form['account']['name']['#field_suffix'] = '<span id="username-check-informer">&nbsp;</span>';
    $form['account']['name']['#suffix'] = '<div id="username-check-message"></div>';
  }
  if ($mailmode != 'off') {
    $form['#attached']['library'] = array(
      'username_check/username_check',
    );
    $form['#attached']['drupalSettings']['usermailCheck']['ajaxUrl'] = $base_url . '/username_check/isuniquemail';
    $form['#attached']['drupalSettings']['usermailCheck']['delay'] = $delay;
    $form['account']['mail']['#field_suffix'] = '<span id="mail-check-informer">&nbsp;</span>';
    $form['account']['mail']['#suffix'] = '<div id="mail-check-message"></div>';
  }
}