You are here

public function UserName::validateArgument in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Plugin/views/argument_validator/UserName.php \Drupal\user\Plugin\views\argument_validator\UserName::validateArgument()

Overrides Entity::validateArgument

File

core/modules/user/src/Plugin/views/argument_validator/UserName.php, line 40
Contains \Drupal\user\Plugin\views\argument_validator\UserName.

Class

UserName
Validates whether a user name is valid.

Namespace

Drupal\user\Plugin\views\argument_validator

Code

public function validateArgument($argument) {
  if ($this->multipleCapable && $this->options['multiple']) {

    // At this point only interested in individual IDs no matter what type,
    // just splitting by the allowed delimiters.
    $names = array_filter(preg_split('/[,+ ]/', $argument));
  }
  elseif ($argument) {
    $names = array(
      $argument,
    );
  }
  else {
    return FALSE;
  }
  $accounts = $this->userStorage
    ->loadByProperties(array(
    'name' => $names,
  ));

  // If there are no accounts, return FALSE now. As we will not enter the
  // loop below otherwise.
  if (empty($accounts)) {
    return FALSE;
  }

  // Validate each account. If any fails break out and return false.
  foreach ($accounts as $account) {
    if (!in_array($account
      ->getUserName(), $names) || !$this
      ->validateEntity($account)) {
      return FALSE;
    }
  }
  return TRUE;
}