You are here

protected function IndividualAccessControlHandler::checkCreateAccess in CRM Core 8

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

Performs create access checks.

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

Parameters

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

array $context: An array of key-value pairs to pass additional context when needed.

string|null $entity_bundle: (optional) The bundle of the entity. Required if the entity supports bundles, defaults to NULL otherwise.

Return value

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

Overrides EntityAccessControlHandler::checkCreateAccess

File

modules/crm_core_contact/src/IndividualAccessControlHandler.php, line 56

Class

IndividualAccessControlHandler
Access control handler for CRM Core Individual entities.

Namespace

Drupal\crm_core_contact

Code

protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
  $individual_type_is_active = empty($entity_bundle);

  // Load the individual type entity.
  if (!empty($entity_bundle)) {

    /* @var \Drupal\crm_core_contact\Entity\IndividualType $individual_type_entity */
    $individual_type_entity = IndividualType::load($entity_bundle);
    $individual_type_is_active = $individual_type_entity
      ->status();
  }
  return AccessResult::allowedIf($individual_type_is_active)
    ->andIf(AccessResult::allowedIfHasPermissions($account, [
    'administer crm_core_individual entities',
    'create crm_core_individual entities',
    'create crm_core_individual entities of bundle ' . $entity_bundle,
  ], 'OR'));
}