You are here

function simplesamlphp_auth_user_form_submit in simpleSAMLphp Authentication 8.3

Form submission handler for user_form.

See also

simplesamlphp_auth_form_user_register_form_alter()

simplesamlphp_auth_form_user_form_alter()

1 string reference to 'simplesamlphp_auth_user_form_submit'
simplesamlphp_auth_user_form_includes in ./simplesamlphp_auth.module
Helper function to include the SimpleSAML checkbox on user forms.

File

./simplesamlphp_auth.module, line 195
SimpleSAMLphp authentication module for Drupal.

Code

function simplesamlphp_auth_user_form_submit($form, FormStateInterface $form_state) {
  $authmap = \Drupal::service('externalauth.authmap');
  $externalauth = \Drupal::service('externalauth.externalauth');

  // Add an authmap entry for this account, so it can leverage SAML
  // authentication.
  if ($form_state
    ->getValue('simplesamlphp_auth_user_enable')) {
    $account = $form_state
      ->getFormObject()
      ->getEntity();

    // Link an authmap entry to this account, if not yet existing.
    // By default, we use the username as authname.
    // This can be altered if needed. See simplesamlphp_auth.api.php for
    // details.
    $authname = $account
      ->getAccountName();
    \Drupal::modulehandler()
      ->alter('simplesamlphp_auth_account_authname', $authname, $account);
    $externalauth
      ->linkExistingAccount($authname, 'simplesamlphp_auth', $account);
  }
  else {
    $authmap
      ->delete($form_state
      ->getValue('uid'));
  }
}