public function CurrentUser::validateArgument in Commerce Core 8.2
Performs validation for a given argument.
Overrides ArgumentValidatorPluginBase::validateArgument
File
- src/
Plugin/ views/ argument_validator/ CurrentUser.php, line 136
Class
- CurrentUser
- Validates whether the argument matches the current user.
Namespace
Drupal\commerce\Plugin\views\argument_validatorCode
public function validateArgument($argument) {
if (!is_numeric($argument)) {
return FALSE;
}
$user_storage = $this->entityTypeManager
->getStorage('user');
$user = $user_storage
->load($argument);
if (!$user instanceof UserInterface) {
return FALSE;
}
if ($user
->isAnonymous()) {
return FALSE;
}
if ($user
->id() == $this->currentUser
->id()) {
return TRUE;
}
if (!empty($this->options['admin_permission'])) {
return $this->currentUser
->hasPermission($this->options['admin_permission']);
}
// Return false by default.
return FALSE;
}