PaymentMethodConfigurationAccessControlHandler.php in Payment 8.2
File
src/Entity/PaymentMethodConfiguration/PaymentMethodConfigurationAccessControlHandler.php
View source
<?php
namespace Drupal\payment\Entity\PaymentMethodConfiguration;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PaymentMethodConfigurationAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
public function __construct(EntityTypeInterface $entity_type, ModuleHandlerInterface $module_handler) {
parent::__construct($entity_type);
$this->moduleHandler = $module_handler;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('module_handler'));
}
protected function checkAccess(EntityInterface $payment_method_configuration, $operation, AccountInterface $account) {
if ($operation == 'enable') {
return AccessResult::allowedIf(!$payment_method_configuration
->status())
->andIf($this
->access($payment_method_configuration, 'update', $account, TRUE))
->addCacheableDependency($payment_method_configuration);
}
elseif ($operation == 'disable') {
return AccessResult::allowedIf($payment_method_configuration
->status())
->andIf($this
->access($payment_method_configuration, 'update', $account, TRUE))
->addCacheableDependency($payment_method_configuration);
}
elseif ($operation == 'duplicate') {
return $this
->createAccess($payment_method_configuration
->bundle(), $account, [], TRUE)
->andIf($this
->access($payment_method_configuration, 'view', $account, TRUE));
}
else {
$permission_prefix = 'payment.payment_method_configuration.' . $operation;
return AccessResult::allowedIfHasPermission($account, $permission_prefix . '.any')
->orIf(AccessResult::allowedIfHasPermission($account, $permission_prefix . '.own')
->andIf(AccessResult::allowedIf($account
->id() == $payment_method_configuration
->getOwnerId())
->addCacheableDependency($payment_method_configuration)));
}
}
protected function checkCreateAccess(AccountInterface $account, array $context, $bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'payment.payment_method_configuration.create.' . $bundle);
}
protected function getCache($cid, $operation, $langcode, AccountInterface $account) {
}
}