You are here

protected function SupportTicketAccessControlHandler::checkAccess in Support Ticketing System 8

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkAccess

File

modules/support_ticket/src/SupportTicketAccessControlHandler.php, line 72
Contains \Drupal\support_ticket\SupportTicketAccessControlHandler.

Class

SupportTicketAccessControlHandler
Defines the access control handler for the support_ticket entity type.

Namespace

Drupal\support_ticket

Code

protected function checkAccess(EntityInterface $support_ticket, $operation, AccountInterface $account) {

  /** @var \Drupal\support_ticket\SupportTicketInterface $support_ticket */

  // Fetch information from the support_ticket object if possible.
  $status = $support_ticket
    ->isPublished();
  $uid = $support_ticket
    ->getOwnerId();

  // Check if authors can view their own unpublished support tickets.
  if ($operation === 'view' && !$status && $account
    ->hasPermission('view own unpublished support tickets') && $account
    ->isAuthenticated() && $account
    ->id() == $uid) {
    return AccessResult::allowed()
      ->cachePerPermissions()
      ->cachePerUser()
      ->cacheUntilEntityChanges($support_ticket);
  }
  if ($operation === 'view') {
    return AccessResult::allowedIf($status)
      ->cacheUntilEntityChanges($support_ticket);
  }

  // No opinion.
  return AccessResult::neutral();
}