You are here

function _cas_add_cas_username_to_user_form in CAS 8

Same name and namespace in other branches
  1. 2.x cas.module \_cas_add_cas_username_to_user_form()

Alter the user entity form to include a textfield for CAS username.

Parameters

array $form: The user entity form.

2 calls to _cas_add_cas_username_to_user_form()
cas_form_user_form_alter in ./cas.module
Implements hook_form_FORM_ID_alter().
cas_form_user_register_form_alter in ./cas.module
Implements hook_form_FORM_ID_alter().

File

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

Code

function _cas_add_cas_username_to_user_form(array &$form) {
  $form['account']['cas_enabled'] = [
    '#type' => 'checkbox',
    '#title' => t('Allow user to log in via CAS'),
    '#access' => \Drupal::currentUser()
      ->hasPermission('administer users'),
    '#weight' => 0,
  ];
  $form['account']['cas_username'] = [
    '#type' => 'textfield',
    '#title' => t('CAS Username'),
    '#description' => t('The username that this user logs into CAS with (typically the same as the Drupal username). Note that while the Drupal password field is required to be filled in, CAS users will not use it to log in.'),
    '#access' => \Drupal::currentUser()
      ->hasPermission('administer users'),
    '#maxlength' => 128,
    '#weight' => 0,
    '#states' => [
      'visible' => [
        ':input[name="cas_enabled"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];

  // We cannot apply form validation method directly to buttons on entity forms
  // anymore so apply it to the whole form instead.
  $form['#validate'][] = '_cas_user_form_validate';
  $form['actions']['submit']['#submit'][] = '_cas_user_form_submit';
}