You are here

protected function OrganizationAccessControlHandler::checkAccess in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_contact/src/OrganizationAccessControlHandler.php \Drupal\crm_core_contact\OrganizationAccessControlHandler::checkAccess()
  2. 8.2 modules/crm_core_contact/src/OrganizationAccessControlHandler.php \Drupal\crm_core_contact\OrganizationAccessControlHandler::checkAccess()

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/crm_core_contact/src/OrganizationAccessControlHandler.php, line 19

Class

OrganizationAccessControlHandler
Access control handler for CRM Core Organization entities.

Namespace

Drupal\crm_core_contact

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  switch ($operation) {
    case 'view':
      return AccessResult::allowedIfHasPermissions($account, [
        'administer crm_core_organization entities',
        'view any crm_core_organization entity',
        'view any crm_core_organization entity of bundle ' . $entity
          ->bundle(),
      ], 'OR');
    case 'update':
      return AccessResult::allowedIfHasPermissions($account, [
        'administer crm_core_organization entities',
        'edit any crm_core_organization entity',
        'edit any crm_core_organization entity of bundle ' . $entity
          ->bundle(),
      ], 'OR');
    case 'delete':
      return AccessResult::allowedIfHasPermissions($account, [
        'administer crm_core_organization entities',
        'delete any crm_core_organization entity',
        'delete any crm_core_organization entity of bundle ' . $entity
          ->bundle(),
      ], 'OR');
    case 'revert':
      return AccessResult::allowedIfHasPermissions($account, [
        'administer crm_core_organization entities',
        'revert organization record',
      ], 'OR');
  }
}