Commit 6827fb07 authored by Brian Osborne's avatar Brian Osborne
Browse files

Issue #3291020 by bkosborne: Fix support for external auth 2.0.x, we must not...

Issue #3291020 by bkosborne: Fix support for external auth 2.0.x, we must not pass NULL to one of its functions.
parent 2c1d8874
Loading
Loading
Loading
Loading
+24 −21
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ function cas_form_user_form_alter(&$form, FormStateInterface $form_state, $form_

  $cas_user_manager = \Drupal::service('cas.user_manager');
  $account = $form_state->getFormObject()->getEntity();
  if (!$account->isNew()) {
    $cas_username = $cas_user_manager->getCasUsernameForAccount($account->id());

    // If a CAS username was found for this user, then populate the CAS username
@@ -71,8 +72,9 @@ function cas_form_user_form_alter(&$form, FormStateInterface $form_state, $form_

          // Users are normally required to entier their current password when
          // changing their password or email address. Since we are disabling
        // access to change their password, and since a CAS user would not know
        // their local Drupal password anyway, we remove this field as well.
          // access to change their password, and since a CAS user would not
          // know their local Drupal password anyway, we remove this field as
          // well.
          if (isset($form['account']['current_pass'])) {
            $form['account']['current_pass']['#access'] = FALSE;
          }
@@ -86,6 +88,7 @@ function cas_form_user_form_alter(&$form, FormStateInterface $form_state, $form_
      }
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
@@ -204,7 +207,7 @@ function _cas_user_form_submit(array $form, FormStateInterface $form_state) {
  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())) {
  elseif ($account->id() && $cas_user_manager->getCasUsernameForAccount($account->id())) {
    $cas_user_manager->removeCasUsernameForAccount($account);
  }
}