You are here

public function CurrentUserOrPermission::validateArgument in Ubercart 8.4

Performs validation for a given argument.

Overrides ArgumentValidatorPluginBase::validateArgument

File

uc_order/src/Plugin/views/argument_validator/CurrentUserOrPermission.php, line 51

Class

CurrentUserOrPermission
Validate whether an argument is the current user or has a permission.

Namespace

Drupal\uc_order\Plugin\views\argument_validator

Code

public function validateArgument($argument) {

  // Check that the user actually exists.
  if (!User::load($argument)) {
    return FALSE;
  }

  // Check if the argument matches the current user ID.
  if (\Drupal::currentUser()
    ->id() == $argument) {
    return TRUE;
  }

  // Check if the current user has the bypass permission.
  if (\Drupal::currentUser()
    ->hasPermission($this->options['perm'])) {
    return TRUE;
  }
  return FALSE;
}