You are here

username_check.module in Username originality AJAX check 8

Same filename and directory in other branches
  1. 5 username_check.module
  2. 6 username_check.module
  3. 7 username_check.module

Checks user name availability on registration page.

File

username_check.module
View source
<?php

/**
 * @file
 * Checks user name availability on registration page.
 */
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>';
  }
}
function username_check_form_user_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');
  $delay = $config
    ->get('username_check_delay');
  if ($mode != 'off') {
    $form['#attached']['library'] = array(
      'username_check/username_check',
    );
    $form['#attached']['drupalSettings']['profileCheck']['ajaxUrl'] = $base_url . '/username_check/isuniqueprofile';
    $form['#attached']['drupalSettings']['profileCheck']['delay'] = $delay;
    $form['account']['name']['#field_suffix'] = '<span id="profile-check-informer">&nbsp;</span>';
    $form['account']['name']['#suffix'] = '<div id="profile-check-message"></div>';
  }
}

Functions

Namesort descending Description
username_check_form_user_form_alter
username_check_form_user_register_form_alter @file Checks user name availability on registration page.