You are here

function _cas_user_form_submit in CAS 2.x

Same name and namespace in other branches
  1. 8 cas.module \_cas_user_form_submit()

Submit callback for the user entity form.

Save (or remove) the association of the CAS username to this edited user.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

1 string reference to '_cas_user_form_submit'
_cas_add_cas_username_to_user_form in ./cas.module
Alter the user entity form to include a textfield for CAS username.

File

./cas.module, line 203
Provides CAS authentication for Drupal.

Code

function _cas_user_form_submit(array $form, FormStateInterface $form_state) {
  $cas_user_manager = \Drupal::service('cas.user_manager');
  $account = $form_state
    ->getFormObject()
    ->getEntity();
  if ($form_state
    ->getValue('cas_username') && $form_state
    ->getValue('cas_enabled')) {
    $cas_user_manager
      ->setCasUsernameForAccount($account, $form_state
      ->getValue('cas_username'));
  }
  elseif ($cas_user_manager
    ->getCasUsernameForAccount($account
    ->id())) {
    $cas_user_manager
      ->removeCasUsernameForAccount($account);
  }
}