function UserName::validateArgument

Same name in other branches
  1. 9 core/modules/user/src/Plugin/views/argument_validator/UserName.php \Drupal\user\Plugin\views\argument_validator\UserName::validateArgument()
  2. 8.9.x core/modules/user/src/Plugin/views/argument_validator/UserName.php \Drupal\user\Plugin\views\argument_validator\UserName::validateArgument()
  3. 11.x 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 36

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 = [
            $argument,
        ];
    }
    else {
        return FALSE;
    }
    $accounts = $this->userStorage
        ->loadByProperties([
        '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->getAccountName(), $names) || !$this->validateEntity($account)) {
            return FALSE;
        }
    }
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.