You are here

class TcaCommerceProductAccessControlHandler in Token Content Access 2.0.x

Same name and namespace in other branches
  1. 8 modules/tca_commerce_product/src/TcaCommerceProductAccessControlHandler.php \Drupal\tca_commerce_product\TcaCommerceProductAccessControlHandler

Extended access control handler for node entity.

Hierarchy

Expanded class hierarchy of TcaCommerceProductAccessControlHandler

1 file declares its use of TcaCommerceProductAccessControlHandler
tca_commerce_product.module in modules/tca_commerce_product/tca_commerce_product.module
Contains tca_commerce_product.module.

File

modules/tca_commerce_product/src/TcaCommerceProductAccessControlHandler.php, line 13

Namespace

Drupal\tca_commerce_product
View source
class TcaCommerceProductAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE) {

    // Allow users without the permission "access content"
    // to 'view' the commerce_product by providing URL token.
    $access = parent::access($entity, $operation, $account, $return_as_object);
    if ($operation === 'view' && $entity
      ->get('tca_active')
      ->getString()) {

      // Compare token from URL with commerce_product token.
      $token_match = $entity
        ->get('tca_token')
        ->getString() === $this
        ->getRequestStack()
        ->getCurrentRequest()
        ->get('tca');
      return $token_match ? AccessResultAllowed::allowed() : $access;
    }
    return $access;
  }

  /**
   * Current request stack.
   *
   * @return \Symfony\Component\HttpFoundation\RequestStack
   *   Request stack.
   */
  protected function getRequestStack() {
    return \Drupal::service('request_stack');
  }

}

Members