You are here

public function ViewPaymentsByOwner::validateArgument in Payment 8.2

Performs validation for a given argument.

Overrides Entity::validateArgument

File

src/Plugin/views/argument_validator/ViewPaymentsByOwner.php, line 49

Class

ViewPaymentsByOwner
Validates whether the current user has access to view a user's payments.

Namespace

Drupal\payment\Plugin\views\argument_validator

Code

public function validateArgument($argument) {
  if (!parent::validateArgument($argument)) {
    return FALSE;
  }

  // Extract the IDs from the argument. See parent::validateArgument().
  if ($this->multipleCapable && $this->options['multiple']) {
    $user_ids = array_filter(preg_split('/[,+ ]/', $argument));
  }
  else {
    $user_ids = [
      $argument,
    ];
  }

  // Allow access when the current user has access to view all payments, or
  // when the current user only tries to view their own payments and has
  // permission to do so.
  return [
    $this->currentUser
      ->id(),
  ] == $user_ids && $this->currentUser
    ->hasPermission('payment.payment.view.own') || $this->currentUser
    ->hasPermission('payment.payment.view.any');
}