-
Notifications
You must be signed in to change notification settings - Fork 0
/
TermAccessControlHandler.php
52 lines (43 loc) · 1.47 KB
/
TermAccessControlHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Contains \Drupal\example_module\ContactAccessControlHandler.
*/
namespace Drupal\example_module;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Access controller for the term entity.
*
* @see \Drupal\example_module\Entity\Term.
*/
class TermAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*
* Link the activities to the permissions. checkAccess is called with the
* $operation as defined in the routing.yml file.
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view dictionary_term entity');
case 'edit':
return AccessResult::allowedIfHasPermission($account, 'edit dictionary_term entity');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete dictionary_term entity');
}
return AccessResult::allowed();
}
/**
* {@inheritdoc}
*
* Separate from the checkAccess because the entity does not yet exist, it
* will be created during the 'add' process.
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add dictionary_term entity');
}
}