public function UserName::validateArgument in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/src/Plugin/views/argument_validator/UserName.php \Drupal\user\Plugin\views\argument_validator\UserName::validateArgument()
- 9 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 35
Class
- UserName
- Validates whether a user name is valid.
Namespace
Drupal\user\Plugin\views\argument_validatorCode
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;
}