function simplesamlphp_auth_form_user_form_alter in simpleSAMLphp Authentication 8.3
Implements hook_form_FORM_ID_alter().
Alters the user register form to include a checkbox signifying the user should be SimpleSAML enabled. Removes password fields if the IdP is the sole place for password management.
See also
AccountForm::form()
simplesamlphp_auth_user_form_submit()
File
- ./
simplesamlphp_auth.module, line 103 - SimpleSAMLphp authentication module for Drupal.
Code
function simplesamlphp_auth_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {
simplesamlphp_auth_user_form_includes($form);
$authmap = \Drupal::service('externalauth.authmap');
// If the user has a simplesamlphp_auth authmap record, then don't require
// them to know their Drupal password. This will allow them to change their
// e-mail address, and set a Drupal password if they want to
// (and are allowed).
$account = $form_state
->getFormObject()
->getEntity();
$saml_enabled = $authmap
->get($account
->id(), 'simplesamlphp_auth');
if ($saml_enabled) {
$form['simplesamlphp_auth_user_enable']['#default_value'] = TRUE;
// If the user is a simplesamlphp_auth user and is NOT allowed to set their
// Drupal password, remove the fields from the form.
$config = \Drupal::config('simplesamlphp_auth.settings');
if (!$config
->get('allow.set_drupal_pwd')) {
$form['account']['current_pass']['#access'] = FALSE;
$form['account']['pass']['#access'] = FALSE;
}
}
}