Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / accesscontrolhandler-entity-content.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{module}}\{{ entity_class }}AccessControlHandler.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{module}};
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Core\Entity\EntityAccessControlHandler;
13 use Drupal\Core\Entity\EntityInterface;
14 use Drupal\Core\Session\AccountInterface;
15 use Drupal\Core\Access\AccessResult;
16 {% endblock %}
17
18 {% block class_declaration %}
19 /**
20  * Access controller for the {{ label }} entity.
21  *
22  * @see \Drupal\{{module}}\Entity\{{ entity_class }}.
23  */
24 class {{ entity_class }}AccessControlHandler extends EntityAccessControlHandler {% endblock %}
25 {% block class_methods %}
26   /**
27    * {@inheritdoc}
28    */
29   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
30     /** @var \Drupal\{{ module }}\Entity\{{ entity_class }}Interface $entity */
31     switch ($operation) {
32       case 'view':
33         if (!$entity->isPublished()) {
34           return AccessResult::allowedIfHasPermission($account, 'view unpublished {{ label|lower }} entities');
35         }
36         return AccessResult::allowedIfHasPermission($account, 'view published {{ label|lower }} entities');
37
38       case 'update':
39         return AccessResult::allowedIfHasPermission($account, 'edit {{ label|lower }} entities');
40
41       case 'delete':
42         return AccessResult::allowedIfHasPermission($account, 'delete {{ label|lower }} entities');
43     }
44
45     // Unknown operation, no opinion.
46     return AccessResult::neutral();
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
53     return AccessResult::allowedIfHasPermission($account, 'add {{ label|lower }} entities');
54   }
55 {% endblock %}