You are here

function Name::validate_user_strings in Views (for Drupal 7) 8.3

Validate the user string. Since this can come from either the form or the exposed filter, this is abstracted out a bit so it can handle the multiple input sources.

2 calls to Name::validate_user_strings()
Name::validateExposed in lib/Views/user/Plugin/views/filter/Name.php
Validate the exposed handler form
Name::value_validate in lib/Views/user/Plugin/views/filter/Name.php
Validate the options form.

File

lib/Views/user/Plugin/views/filter/Name.php, line 114
Definition of Views\user\Plugin\views\filter\Name.

Class

Name
Filter handler for usernames.

Namespace

Views\user\Plugin\views\filter

Code

function validate_user_strings(&$form, $values) {
  $uids = array();
  $placeholders = array();
  $args = array();
  $results = array();
  foreach ($values as $value) {
    if (strtolower($value) == 'anonymous') {
      $uids[] = 0;
    }
    else {
      $missing[strtolower($value)] = TRUE;
      $args[] = $value;
      $placeholders[] = "'%s'";
    }
  }
  if (!$args) {
    return $uids;
  }
  $result = entity_load_multiple_by_properties('user', array(
    'name' => $args,
  ));
  foreach ($result as $account) {
    unset($missing[strtolower($account->name)]);
    $uids[] = $account->uid;
  }
  if ($missing) {
    form_error($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array(
      '@users' => implode(', ', array_keys($missing)),
    )));
  }
  return $uids;
}