Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Entity;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Field\FieldItemListInterface;
|
Chris@0
|
6 use Drupal\Core\Extension\ModuleHandlerInterface;
|
Chris@0
|
7 use Drupal\Core\Field\FieldDefinitionInterface;
|
Chris@0
|
8 use Drupal\Core\Session\AccountInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Defines an interface for entity access control handlers.
|
Chris@0
|
12 */
|
Chris@0
|
13 interface EntityAccessControlHandlerInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Checks access to an operation on a given entity or entity translation.
|
Chris@0
|
17 *
|
Chris@0
|
18 * Use \Drupal\Core\Entity\EntityAccessControlHandlerInterface::createAccess()
|
Chris@0
|
19 * to check access to create an entity.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @param \Drupal\Core\Entity\EntityInterface $entity
|
Chris@0
|
22 * The entity for which to check access.
|
Chris@0
|
23 * @param string $operation
|
Chris@0
|
24 * The operation access should be checked for.
|
Chris@0
|
25 * Usually one of "view", "view label", "update" or "delete".
|
Chris@0
|
26 * @param \Drupal\Core\Session\AccountInterface $account
|
Chris@0
|
27 * (optional) The user session for which to check access, or NULL to check
|
Chris@0
|
28 * access for the current user. Defaults to NULL.
|
Chris@0
|
29 * @param bool $return_as_object
|
Chris@0
|
30 * (optional) Defaults to FALSE.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @return bool|\Drupal\Core\Access\AccessResultInterface
|
Chris@0
|
33 * The access result. Returns a boolean if $return_as_object is FALSE (this
|
Chris@0
|
34 * is the default) and otherwise an AccessResultInterface object.
|
Chris@0
|
35 * When a boolean is returned, the result of AccessInterface::isAllowed() is
|
Chris@0
|
36 * returned, i.e. TRUE means access is explicitly allowed, FALSE means
|
Chris@0
|
37 * access is either explicitly forbidden or "no opinion".
|
Chris@0
|
38 */
|
Chris@0
|
39 public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE);
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * Checks access to create an entity.
|
Chris@0
|
43 *
|
Chris@0
|
44 * @param string $entity_bundle
|
Chris@0
|
45 * (optional) The bundle of the entity. Required if the entity supports
|
Chris@0
|
46 * bundles, defaults to NULL otherwise.
|
Chris@0
|
47 * @param \Drupal\Core\Session\AccountInterface $account
|
Chris@0
|
48 * (optional) The user session for which to check access, or NULL to check
|
Chris@0
|
49 * access for the current user. Defaults to NULL.
|
Chris@0
|
50 * @param array $context
|
Chris@0
|
51 * (optional) An array of key-value pairs to pass additional context when
|
Chris@0
|
52 * needed.
|
Chris@0
|
53 * @param bool $return_as_object
|
Chris@0
|
54 * (optional) Defaults to FALSE.
|
Chris@0
|
55 *
|
Chris@0
|
56 * @return bool|\Drupal\Core\Access\AccessResultInterface
|
Chris@0
|
57 * The access result. Returns a boolean if $return_as_object is FALSE (this
|
Chris@0
|
58 * is the default) and otherwise an AccessResultInterface object.
|
Chris@0
|
59 * When a boolean is returned, the result of AccessInterface::isAllowed() is
|
Chris@0
|
60 * returned, i.e. TRUE means access is explicitly allowed, FALSE means
|
Chris@0
|
61 * access is either explicitly forbidden or "no opinion".
|
Chris@0
|
62 */
|
Chris@0
|
63 public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = [], $return_as_object = FALSE);
|
Chris@0
|
64
|
Chris@0
|
65 /**
|
Chris@0
|
66 * Clears all cached access checks.
|
Chris@0
|
67 */
|
Chris@0
|
68 public function resetCache();
|
Chris@0
|
69
|
Chris@0
|
70 /**
|
Chris@0
|
71 * Sets the module handler for this access control handler.
|
Chris@0
|
72 *
|
Chris@0
|
73 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
Chris@0
|
74 * The module handler.
|
Chris@0
|
75 *
|
Chris@0
|
76 * @return $this
|
Chris@0
|
77 */
|
Chris@0
|
78 public function setModuleHandler(ModuleHandlerInterface $module_handler);
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * Checks access to an operation on a given entity field.
|
Chris@0
|
82 *
|
Chris@0
|
83 * This method does not determine whether access is granted to the entity
|
Chris@0
|
84 * itself, only the specific field. Callers are responsible for ensuring that
|
Chris@0
|
85 * entity access is also respected, for example by using
|
Chris@0
|
86 * \Drupal\Core\Entity\EntityAccessControlHandlerInterface::access().
|
Chris@0
|
87 *
|
Chris@0
|
88 * @param string $operation
|
Chris@0
|
89 * The operation access should be checked for.
|
Chris@0
|
90 * Usually one of "view" or "edit".
|
Chris@0
|
91 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
|
Chris@0
|
92 * The field definition.
|
Chris@0
|
93 * @param \Drupal\Core\Session\AccountInterface $account
|
Chris@0
|
94 * (optional) The user session for which to check access, or NULL to check
|
Chris@0
|
95 * access for the current user. Defaults to NULL.
|
Chris@0
|
96 * @param \Drupal\Core\Field\FieldItemListInterface $items
|
Chris@0
|
97 * (optional) The field values for which to check access, or NULL if access
|
Chris@0
|
98 * is checked for the field definition, without any specific value
|
Chris@0
|
99 * available. Defaults to NULL.
|
Chris@0
|
100 * @param bool $return_as_object
|
Chris@0
|
101 * (optional) Defaults to FALSE.
|
Chris@0
|
102 *
|
Chris@0
|
103 * @return bool|\Drupal\Core\Access\AccessResultInterface
|
Chris@0
|
104 * The access result. Returns a boolean if $return_as_object is FALSE (this
|
Chris@0
|
105 * is the default) and otherwise an AccessResultInterface object.
|
Chris@0
|
106 * When a boolean is returned, the result of AccessInterface::isAllowed() is
|
Chris@0
|
107 * returned, i.e. TRUE means access is explicitly allowed, FALSE means
|
Chris@0
|
108 * access is either explicitly forbidden or "no opinion".
|
Chris@0
|
109 *
|
Chris@0
|
110 * @see \Drupal\Core\Entity\EntityAccessControlHandlerInterface::access()
|
Chris@0
|
111 */
|
Chris@0
|
112 public function fieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account = NULL, FieldItemListInterface $items = NULL, $return_as_object = FALSE);
|
Chris@0
|
113
|
Chris@0
|
114 }
|