ActivityAccessControlHandler.php in CRM Core 8.3
File
modules/crm_core_activity/src/ActivityAccessControlHandler.php
View source
<?php
namespace Drupal\crm_core_activity;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\crm_core_activity\Entity\ActivityType;
class ActivityAccessControlHandler extends EntityAccessControlHandler {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermissions($account, [
'administer crm_core_activity entities',
'view any crm_core_activity entity',
'view any crm_core_activity entity of bundle ' . $entity
->bundle(),
], 'OR');
case 'update':
return AccessResult::allowedIfHasPermissions($account, [
'administer crm_core_activity entities',
'edit any crm_core_activity entity',
'edit any crm_core_activity entity of bundle ' . $entity
->bundle(),
], 'OR');
case 'delete':
return AccessResult::allowedIfHasPermissions($account, [
'administer crm_core_activity entities',
'delete any crm_core_activity entity',
'delete any crm_core_activity entity of bundle ' . $entity
->bundle(),
], 'OR');
}
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
$activity_type_is_active = !empty($entity_bundle);
if ($activity_type_is_active) {
$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'));
}
}