protected function ActivityTypeAccessControlHandler::checkAccess in CRM Core 8.3
Same name and namespace in other branches
- 8 modules/crm_core_activity/src/ActivityTypeAccessControlHandler.php \Drupal\crm_core_activity\ActivityTypeAccessControlHandler::checkAccess()
- 8.2 modules/crm_core_activity/src/ActivityTypeAccessControlHandler.php \Drupal\crm_core_activity\ActivityTypeAccessControlHandler::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_activity/ src/ ActivityTypeAccessControlHandler.php, line 18
Class
- ActivityTypeAccessControlHandler
- Activity Type Access Control Handler.
Namespace
Drupal\crm_core_activityCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
// First check drupal permission.
if (parent::checkAccess($entity, $operation, $account)
->isForbidden()) {
return AccessResult::forbidden();
}
switch ($operation) {
case 'enable':
// Only disabled activity type can be enabled.
return AccessResult::allowedIf(!$entity
->status());
case 'disable':
return AccessResult::allowedIf($entity
->status());
case 'delete':
// If the activity instance of this activity type exist, you can't
// delete it.
$count = \Drupal::entityQuery('crm_core_activity')
->condition('type', $entity
->id())
->count()
->execute();
return AccessResult::allowedIf($count == 0);
case 'view':
case 'update':
return AccessResult::allowed();
}
}