You are here

class ViewPaymentsByOwner in Payment 8.2

Same name in this branch
  1. 8.2 src/Controller/ViewPaymentsByOwner.php \Drupal\payment\Controller\ViewPaymentsByOwner
  2. 8.2 src/Plugin/views/argument_validator/ViewPaymentsByOwner.php \Drupal\payment\Plugin\views\argument_validator\ViewPaymentsByOwner

Handles the "view payments by owner" route.

Hierarchy

Expanded class hierarchy of ViewPaymentsByOwner

File

src/Controller/ViewPaymentsByOwner.php, line 15

Namespace

Drupal\payment\Controller
View 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

Namesort descending Modifiers Type Description Overrides
ViewPaymentsByOwner::$currentUser protected property The current user.
ViewPaymentsByOwner::$paymentListBuilder protected property The payment list builder.
ViewPaymentsByOwner::access public function Checks access to the route.
ViewPaymentsByOwner::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ViewPaymentsByOwner::execute public function Executes the route.
ViewPaymentsByOwner::__construct public function Creates a new instance.