class ViewPaymentsByOwner in Payment 8.2
Same name in this branch
- 8.2 src/Controller/ViewPaymentsByOwner.php \Drupal\payment\Controller\ViewPaymentsByOwner
- 8.2 src/Plugin/views/argument_validator/ViewPaymentsByOwner.php \Drupal\payment\Plugin\views\argument_validator\ViewPaymentsByOwner
Handles the "view payments by owner" route.
Hierarchy
- class \Drupal\payment\Controller\ViewPaymentsByOwner implements ContainerInjectionInterface
Expanded class hierarchy of ViewPaymentsByOwner
File
- src/
Controller/ ViewPaymentsByOwner.php, line 15
Namespace
Drupal\payment\ControllerView source
class ViewPaymentsByOwner implements ContainerInjectionInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The payment list builder.
*
* @var \Drupal\payment\Entity\Payment\PaymentListBuilderInterface
*/
protected $paymentListBuilder;
/**
* Creates a new instance.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* @param \Drupal\payment\Entity\Payment\PaymentListBuilderInterface $payment_list_builder
*/
public function __construct(AccountInterface $current_user, PaymentListBuilderInterface $payment_list_builder) {
$this->currentUser = $current_user;
$this->paymentListBuilder = $payment_list_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $container
->get('entity_type.manager');
return new static($container
->get('current_user'), $entity_type_manager
->getListBuilder('payment'));
}
/**
* Executes the route.
*
* @param \Drupal\user\UserInterface $user
*
* @return array
* A render array.
*/
public function execute(UserInterface $user) {
$this->paymentListBuilder
->restrictByOwnerId($user
->id());
return $this->paymentListBuilder
->render();
}
/**
* Checks access to the route.
*
* @param \Drupal\user\UserInterface $user
*
* @return \Drupal\Core\Access\AccessResultInterface
*/
public function access(UserInterface $user) {
return AccessResult::allowedIf($this->currentUser
->id() == $user
->id() && $this->currentUser
->hasPermission('payment.payment.view.own'))
->orIf(AccessResult::allowedIf($this->currentUser
->hasPermission('payment.payment.view.any')));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ViewPaymentsByOwner:: |
protected | property | The current user. | |
ViewPaymentsByOwner:: |
protected | property | The payment list builder. | |
ViewPaymentsByOwner:: |
public | function | Checks access to the route. | |
ViewPaymentsByOwner:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ViewPaymentsByOwner:: |
public | function | Executes the route. | |
ViewPaymentsByOwner:: |
public | function | Creates a new instance. |