You are here

protected function ActivityAccessControlHandler::checkCreateAccess in CRM Core 8.3

Same name and namespace in other branches
  1. 8 modules/crm_core_activity/src/ActivityAccessControlHandler.php \Drupal\crm_core_activity\ActivityAccessControlHandler::checkCreateAccess()
  2. 8.2 modules/crm_core_activity/src/ActivityAccessControlHandler.php \Drupal\crm_core_activity\ActivityAccessControlHandler::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_activity/src/ActivityAccessControlHandler.php, line 48

Class

ActivityAccessControlHandler
Access control handler for CRM Core Activity entities.

Namespace

Drupal\crm_core_activity

Code

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

  // Load the activity type entity.
  if ($activity_type_is_active) {

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