forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccesscontrolhandler-entity-content.php.twig
More file actions
51 lines (42 loc) · 1.47 KB
/
Copy pathaccesscontrolhandler-entity-content.php.twig
File metadata and controls
51 lines (42 loc) · 1.47 KB
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
{% extends "base/class.php.twig" %}
{% block file_path %}
Drupal\{{module}}\{{ entity_class }}AccessControlHandler.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
{% endblock %}
{% block class_declaration %}
/**
* Access controller for the {{ entity_class }} entity.
*
* @see \Drupal\{{module}}\Entity\{{ entity_class }}.
*/
class {{ entity_class }}AccessControlHandler extends EntityAccessControlHandler {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view {{ entity_class }} entity');
case 'edit':
return AccessResult::allowedIfHasPermission($account, 'edit {{ entity_class }} entity');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete {{ entity_class }} entity');
}
return AccessResult::allowed();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add {{ entity_class }} entity');
}
{% endblock %}