You are here

function social_user_register_validate in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/social_user.module \social_user_register_validate()
  2. 8 modules/social_features/social_user/social_user.module \social_user_register_validate()
  3. 8.2 modules/social_features/social_user/social_user.module \social_user_register_validate()
  4. 8.3 modules/social_features/social_user/social_user.module \social_user_register_validate()
  5. 8.5 modules/social_features/social_user/social_user.module \social_user_register_validate()
  6. 8.6 modules/social_features/social_user/social_user.module \social_user_register_validate()
  7. 8.7 modules/social_features/social_user/social_user.module \social_user_register_validate()
  8. 8.8 modules/social_features/social_user/social_user.module \social_user_register_validate()
  9. 10.3.x modules/social_features/social_user/social_user.module \social_user_register_validate()
  10. 10.0.x modules/social_features/social_user/social_user.module \social_user_register_validate()
  11. 10.1.x modules/social_features/social_user/social_user.module \social_user_register_validate()
  12. 10.2.x modules/social_features/social_user/social_user.module \social_user_register_validate()

Validate function for the user register form.

1 string reference to 'social_user_register_validate'
social_user_form_user_register_form_alter in modules/social_features/social_user/social_user.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_user/social_user.module, line 112
The social user module alterations.

Code

function social_user_register_validate(&$form, FormStateInterface $form_state) {

  // Fetch input.
  $input = $form_state
    ->getValues();

  // Check if mail or username already exist.
  if (user_load_by_mail($input['mail']) || user_load_by_name($input['name'])) {

    // If either the username or mail already exists in the DB, we clear ALL
    // existing messages, making sure nothing about this is being disclosed.
    $form_state
      ->clearErrors();

    // Set a new more general error.
    $site_config = \Drupal::config('system.site');
    $site_mail = $site_config
      ->get('mail');
    $show_mail = $site_config
      ->get('show_mail_in_messages');
    $admin_link = $site_mail && $show_mail ? Link::fromTextAndUrl(t('site administrator'), Url::fromUri('mailto:' . $site_mail))
      ->toString() : t('site administrator');
    $form_state
      ->setErrorByName('mail', t("Oops, there was an error with the email address or username you entered. Due to privacy concerns, we can't disclose the existence of already registered email addresses.\n    So, please try again! Contact the @admin_link if there are any problems.", [
      '@admin_link' => $admin_link,
    ]));
  }
}