Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CrmCaseAccessControlHandler | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| checkAccess | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
5 | |||
| checkCreateAccess | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\crm_case; |
| 4 | |
| 5 | use Drupal\Core\Access\AccessResult; |
| 6 | use Drupal\Core\Entity\EntityAccessControlHandler; |
| 7 | use Drupal\Core\Entity\EntityInterface; |
| 8 | use Drupal\Core\Session\AccountInterface; |
| 9 | |
| 10 | /** |
| 11 | * Defines the access control handler for the crm case entity type. |
| 12 | */ |
| 13 | class CrmCaseAccessControlHandler extends EntityAccessControlHandler { |
| 14 | |
| 15 | /** |
| 16 | * {@inheritdoc} |
| 17 | */ |
| 18 | protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { |
| 19 | |
| 20 | switch ($operation) { |
| 21 | case 'view': |
| 22 | return AccessResult::allowedIfHasPermissions( |
| 23 | $account, |
| 24 | ['view crm case', 'administer crm'], |
| 25 | 'OR', |
| 26 | ); |
| 27 | |
| 28 | case 'update': |
| 29 | return AccessResult::allowedIfHasPermissions( |
| 30 | $account, |
| 31 | ['edit crm case', 'administer crm'], |
| 32 | 'OR', |
| 33 | ); |
| 34 | |
| 35 | case 'delete': |
| 36 | return AccessResult::allowedIfHasPermissions( |
| 37 | $account, |
| 38 | ['delete crm case', 'administer crm'], |
| 39 | 'OR', |
| 40 | ); |
| 41 | |
| 42 | default: |
| 43 | // No opinion. |
| 44 | return AccessResult::neutral(); |
| 45 | } |
| 46 | |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * {@inheritdoc} |
| 51 | */ |
| 52 | protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { |
| 53 | return AccessResult::allowedIfHasPermissions( |
| 54 | $account, |
| 55 | ['create crm case', 'administer crm'], |
| 56 | 'OR', |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | } |