argument->options['validate_user_argument_type'])) { $this->argument->options['validate_user_argument_type'] = 'uid'; } $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' => '
', '#suffix' => '
', ); } function validate_argument($argument) { $type = $this->argument->options['validate_user_argument_type']; // is_numeric() can return false positives, so we ensure it's an integer. // However, is_integer() will always fail, since $argument is a string. if (is_numeric($argument) && $argument == (int)$argument) { if ($type == 'uid' || $type == 'either') { $where = 'u.uid = %d'; } } else { if ($type == 'name' || $type == 'either') { $where = "u.name = '%s'"; } } if (!empty($where)) { $query = db_rewrite_sql("SELECT u.uid FROM {users} u WHERE {$where}", 'u', 'uid', array($argument)); $validated = db_result(db_query($query, $argument)); return $validated; } return FALSE; } }