You are here

function masquerade_admin_settings_validate in Masquerade 7

Same name and namespace in other branches
  1. 6 masquerade.module \masquerade_admin_settings_validate()
1 string reference to 'masquerade_admin_settings_validate'
masquerade_admin_settings in ./masquerade.module
Admin settings form.

File

./masquerade.module, line 306
The masquerade module allows administrators to masquerade as other user.

Code

function masquerade_admin_settings_validate($form, &$form_state) {
  if (!empty($form_state['values']['masquerade_test_user'])) {
    $test_user = _masquerade_user_load($form_state['values']['masquerade_test_user']);
    if (!$test_user) {
      form_set_error('masquerade_test_user', t('%user does not exist. Please enter a valid username.', array(
        '%user' => $form_state['values']['masquerade_test_user'],
      )));
    }
  }

  // Needs to rebuild menu in masquerade_admin_settings_submit().
  $form_state['masquerade_rebuild_menu'] = variable_get('masquerade_test_user', '') != $form_state['values']['masquerade_test_user'];

  // A comma-separated list of users.
  $masquerade_switches = drupal_explode_tags($form_state['values']['masquerade_quick_switches']);

  // Change user names to user ID's for system_settings_form_submit() to save.
  $masquerade_uids = array();
  foreach ($masquerade_switches as $switch_user) {
    $test_user = _masquerade_user_load($switch_user);
    if (!$test_user) {
      form_set_error('masquerade_quick_switches', t('%user does not exist. Please enter a valid username.', array(
        '%user' => $switch_user,
      )));
    }
    else {
      $masquerade_uids[] = $test_user->uid;
    }
  }
  $form_state['values']['masquerade_quick_switches'] = $masquerade_uids;
}