You are here

function ldap_user_form_register_form_submit2 in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.2 ldap_user/ldap_user.module \ldap_user_form_register_form_submit2()
  2. 8.3 ldap_user/ldap_user.module \ldap_user_form_register_form_submit2()
  3. 7.2 ldap_user/ldap_user.module \ldap_user_form_register_form_submit2()

Called after user_register_form_submit.

1 string reference to 'ldap_user_form_register_form_submit2'
ldap_user_form_user_register_form_alter in ldap_user/ldap_user.module
Implements hook_form_FORM_ID_alter().

File

ldap_user/ldap_user.module, line 426

Code

function ldap_user_form_register_form_submit2(&$form, FormState $form_state) {

  // It's only called when a user who can create a new user does so using the
  // register form.
  $values = $form_state
    ->getValues();

  /** @var \Drupal\ldap_user\Processor\DrupalUserProcessor $userProcessor */
  $userProcessor = \Drupal::service('ldap.drupal_user_processor');
  if ($values['ldap_user_association'] === LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_NO_LDAP_ASSOCIATE) {
    $userProcessor
      ->ldapExcludeDrupalAccount($values['name']);
  }
  elseif ($values['ldap_user_association'] === LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_LDAP_ASSOCIATE) {

    // Either LDAP provision (above) has said "associate" or the person creating
    // the account has said "associate" or the LDAP user settings says
    // "Associate manually created Drupal accounts with related LDAP Account
    // if one exists.".
    $association = $userProcessor
      ->ldapAssociateDrupalAccount($values['name']);
    if (!$association) {
      \Drupal::messenger()
        ->addWarning(t('Account created but no LDAP account found to associate with.'));
    }
  }
}