ViewPaymentsByOwner.php in Payment 8.2
File
src/Plugin/views/argument_validator/ViewPaymentsByOwner.php
View source
<?php
namespace Drupal\payment\Plugin\views\argument_validator;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Plugin\views\argument_validator\User;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ViewPaymentsByOwner extends User {
protected $currentUser;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$argument_validator = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$argument_validator->currentUser = $container
->get('current_user');
return $argument_validator;
}
public function setCurrentUser(AccountInterface $current_user) {
$this->currentUser = $current_user;
}
public function validateArgument($argument) {
if (!parent::validateArgument($argument)) {
return FALSE;
}
if ($this->multipleCapable && $this->options['multiple']) {
$user_ids = array_filter(preg_split('/[,+ ]/', $argument));
}
else {
$user_ids = [
$argument,
];
}
return [
$this->currentUser
->id(),
] == $user_ids && $this->currentUser
->hasPermission('payment.payment.view.own') || $this->currentUser
->hasPermission('payment.payment.view.any');
}
}