Commit 75dcf0c9 authored by Milos Bovan's avatar Milos Bovan Committed by Jonathan Sacksick
Browse files

Issue #3116643 by mbovan, bojanz, Berdir: Allow "view label" permission for...

Issue #3116643 by mbovan, bojanz, Berdir: Allow "view label" permission for Payment Gateway entities.
parent cb2f6fa7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
 *     plural = "@count payment gateways",
 *   ),
 *   handlers = {
 *     "access" = "Drupal\commerce_payment\PaymentGatewayAccessControlHandler",
 *     "list_builder" = "Drupal\commerce_payment\PaymentGatewayListBuilder",
 *     "storage" = "Drupal\commerce_payment\PaymentGatewayStorage",
 *     "form" = {
+37 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\commerce_payment;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Controls access to payment gateway entities.
 *
 * Allows the payment gateway entity label to be viewed if a user has
 * administrative permission or can manage own payment methods.
 */
class PaymentGatewayAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected $viewLabelOperation = TRUE;

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    if ($operation === 'view label') {
      return AccessResult::allowedIfHasPermissions($account, [
        $this->entityType->getAdminPermission(),
        'manage own commerce_payment_method',
      ], 'OR');
    }

    return parent::checkAccess($entity, $operation, $account);
  }

}