You are here

function userprotect_form_alter in User protect 7

Same name and namespace in other branches
  1. 5 userprotect.module \userprotect_form_alter()
  2. 6 userprotect.module \userprotect_form_alter()

Implements hook_form_alter().

File

./userprotect.module, line 123
Main module file for the userprotect module.

Code

function userprotect_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {

    // These are complex cases, and are best handled by manipulating the form
    // values in a custom validate function.
    case 'user_admin_account':
    case 'user_multiple_cancel_confirm':

      // Ensure an array.
      $form['#validate'] = isset($form['#validate']) ? $form['#validate'] : array();
      array_unshift($form['#validate'], 'userprotect_user_admin_account_validate');
      break;
    case 'openid_user_add':
    case 'openid_user_delete_form':
      $account = menu_get_object('user');
      $protected = array();
      if (!userprotect_check_bypass('up_openid') && userprotect_get_user_protection($account, 'up_openid')) {
        switch ($form_id) {
          case 'openid_user_add':
            if (isset($form['openid_identifier'])) {
              $form['openid_identifier']['#disabled'] = TRUE;
              $form['actions']['submit']['#disabled'] = TRUE;
            }
            break;
          case 'openid_user_delete_form':
            if (isset($form['actions']['submit'])) {
              $form['actions']['submit']['#disabled'] = TRUE;
              $form['confirm']['#value'] = 0;
            }
            break;
        }
        $protected['up_openid'] = TRUE;
      }
      userprotect_form_display_protections($account, $protected);
      break;
  }
}