function ldap_user_form_user_register_form_alter in Lightweight Directory Access Protocol (LDAP) 8.4
Same name and namespace in other branches
- 8.2 ldap_user/ldap_user.module \ldap_user_form_user_register_form_alter()
- 8.3 ldap_user/ldap_user.module \ldap_user_form_user_register_form_alter()
- 7.2 ldap_user/ldap_user.module \ldap_user_form_user_register_form_alter()
Implements hook_form_FORM_ID_alter().
For user_register_form.
File
- ldap_user/
ldap_user.module, line 275
Code
function ldap_user_form_user_register_form_alter(&$form, $form_state) {
$user_settings = \Drupal::config('ldap_user.settings');
array_unshift($form['#submit'], 'ldap_user_grab_password_validate');
if (!\Drupal::currentUser()
->hasPermission('administer users')) {
return;
}
if ($user_settings
->get('disableAdminPasswordField') == TRUE) {
$form['account']['pass']['#type'] = 'value';
if (version_compare(\Drupal::VERSION, '9.1', '>=')) {
$form['account']['pass']['#value'] = \Drupal::service('password_generator')
->generate(40);
}
else {
$form['account']['pass']['#value'] = user_password(40);
}
$form['account']['pass_disabled']['#type'] = 'fieldset';
$form['account']['pass_disabled']['#title'] = t('Password');
$form['account']['pass_disabled'][]['#markup'] = t('LDAP has disabled the password field and generated a random password.');
}
$form['ldap_user_fields']['#type'] = 'fieldset';
$form['ldap_user_fields']['#title'] = t('LDAP Options');
$form['ldap_user_fields']['#description'] = t('By enabling options in the LDAP user configuration, you can allow the creation of LDAP accounts and define the conflict resolution for associated accounts.');
$form['ldap_user_fields']['#collapsible'] = TRUE;
$form['ldap_user_fields']['#collapsed'] = FALSE;
$form['ldap_user_fields']['ldap_user_association'] = [
'#type' => 'radios',
'#options' => [
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_LDAP_ASSOCIATE => t('Associate account'),
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_NO_LDAP_ASSOCIATE => t('Do not associated account'),
],
'#description' => t('If you choose associated account and an LDAP account cannot be found, a validation error will appear and the account will not be created.'),
'#title' => t('LDAP Entry Association.'),
];
if ($user_settings
->get('ldapEntryProvisionTriggers') && in_array(LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_UPDATE_CREATE, $user_settings
->get('ldapEntryProvisionTriggers'), TRUE)) {
$form['ldap_user_fields']['ldap_user_association']['#access'] = FALSE;
}
elseif ($user_settings
->get('manualAccountConflict') !== LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_SHOW_OPTION_ON_FORM) {
$form['ldap_user_fields']['ldap_user_association']['#access'] = FALSE;
}
else {
$form['ldap_user_fields']['ldap_user_association']['#default_value'] = LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_LDAP_ASSOCIATE;
}
$form['ldap_user_fields']['ldap_user_create_ldap_acct'] = [
'#type' => 'checkbox',
'#title' => t('Create corresponding LDAP entry.'),
];
if (!in_array(LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_ON_MANUAL_CREATION, $user_settings
->get('ldapEntryProvisionTriggers'), TRUE)) {
$form['ldap_user_fields']['ldap_user_create_ldap_acct']['#access'] = FALSE;
}
$form['#validate'][] = 'ldap_user_form_register_form_validate';
foreach (array_keys($form['actions']) as $action) {
if (isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'ldap_user_form_register_form_submit2';
}
}
}