You are here

function hook_support_ticket_access in Support Ticketing System 8

Controls access to a support ticket.

Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a support ticket.

Note that not all modules will want to influence access on all support ticket types. If your module does not want to explicitly allow or forbid access, return an AccessResultInterface object with neither isAllowed() nor isForbidden() equaling TRUE. Blindly returning an object with isForbidden() equaling TRUE will break other support ticket access modules.

Parameters

\Drupal\support_ticket\SupportTicketInterface|string $support_ticket: Either a support ticket entity or the machine name of the content type on which to perform the access check.

string $op: The operation to be performed. Possible values:

  • "create"
  • "delete"
  • "update"
  • "view"

\Drupal\Core\Session\AccountInterface $account: The user object to perform the access check operation on.

Return value

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

1 function implements hook_support_ticket_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

support_ticket_support_ticket_access in modules/support_ticket/support_ticket.module
Implements hook_support_ticket_access().

File

modules/support_ticket/support_ticket.api.php, line 45
Hooks specific to the Support ticket module.

Code

function hook_support_ticket_access(\Drupal\support_ticket\SupportTicketInterface $support_ticket, $op, \Drupal\Core\Session\AccountInterface $account) {
  $type = $support_ticket
    ->bundle();
  switch ($op) {
    case 'create':
      return AccessResult::allowedIfHasPermission($account, 'create ' . $type . ' ticket');
    case 'update':
      if ($account
        ->hasPermission('edit any ' . $type . ' ticket')) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('edit own ' . $type . ' ticket') && $account
          ->id() == $support_ticket
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($support_ticket);
      }
    case 'delete':
      if ($account
        ->hasPermission('delete any ' . $type . ' ticket')) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      else {
        return AccessResult::allowedIf($account
          ->hasPermission('delete own ' . $type . ' ticket') && $account
          ->id() == $support_ticket
          ->getOwnerId())
          ->cachePerPermissions()
          ->cachePerUser()
          ->cacheUntilEntityChanges($support_ticket);
      }
    default:

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