TcaCommerceProductAccessControlHandler.php in Token Content Access 2.0.x
File
modules/tca_commerce_product/src/TcaCommerceProductAccessControlHandler.php
View source
<?php
namespace Drupal\tca_commerce_product;
use Drupal\Core\Access\AccessResultAllowed;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\entity\EntityAccessControlHandler;
class TcaCommerceProductAccessControlHandler extends EntityAccessControlHandler {
public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
$access = parent::access($entity, $operation, $account, $return_as_object);
if ($operation === 'view' && $entity
->get('tca_active')
->getString()) {
$token_match = $entity
->get('tca_token')
->getString() === $this
->getRequestStack()
->getCurrentRequest()
->get('tca');
return $token_match ? AccessResultAllowed::allowed() : $access;
}
return $access;
}
protected function getRequestStack() {
return \Drupal::service('request_stack');
}
}