You are here

function views_plugin_argument_validate_user::validate_form in Views (for Drupal 7) 6.2

Overrides views_plugin_argument_validate::validate_form

File

modules/user/views_plugin_argument_validate_user.inc, line 11

Class

views_plugin_argument_validate_user
Validate whether an argument is a valid user.

Code

function validate_form(&$form, &$form_state) {

  // We are unable to rely on options having already been set, so let's make
  // sure defaults are here:
  if (!isset($this->argument->options['validate_user_argument_type'])) {
    $this->argument->options['validate_user_argument_type'] = 'uid';
    $this->argument->options['validate_user_roles'] = array();
  }
  $form['validate_user_argument_type'] = array(
    '#type' => 'radios',
    '#title' => t('Type of user argument to allow'),
    '#options' => array(
      'uid' => t('Only allow numeric UIDs'),
      'name' => t('Only allow string usernames'),
      'either' => t('Allow both numeric UIDs and string usernames'),
    ),
    '#default_value' => $this->argument->options['validate_user_argument_type'],
    '#process' => array(
      'expand_radios',
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
    '#prefix' => '<div id="edit-options-validate-user-argument-type-wrapper">',
    '#suffix' => '</div>',
  );
  $form['validate_user_restrict_roles'] = array(
    '#type' => 'checkbox',
    '#title' => t('Restrict user based on role'),
    '#default_value' => !empty($this->argument->options['validate_user_restrict_roles']),
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
  );
  $form['validate_user_roles'] = array(
    '#type' => 'checkboxes',
    '#prefix' => '<div id="edit-options-validate-user-roles-wrapper">',
    '#suffix' => '</div>',
    '#title' => t('Restrict to the selected roles'),
    '#options' => user_roles(TRUE),
    '#default_value' => $this->argument->options['validate_user_roles'],
    '#description' => t('If no roles are selected, users from any role will be allowed.'),
    '#process' => array(
      'expand_checkboxes',
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
      'edit-options-validate-user-restrict-roles' => array(
        1,
      ),
    ),
    '#dependency_count' => 2,
  );
}