Commit | Line | Data |
---|---|---|
7422a230 TO |
1 | <?php |
2 | ||
3 | namespace Civi\Api4; | |
4 | ||
dc36dc4d | 5 | use Civi\Api4\Generic\BasicGetFieldsAction; |
7422a230 TO |
6 | |
7 | /** | |
7d54c92c CW |
8 | * User-configurable forms. |
9 | * | |
10 | * Afform stands for *The Affable Administrative Angular Form Framework*. | |
11 | * | |
12 | * This API provides actions for | |
13 | * 1. **_Managing_ forms:** | |
14 | * The `create`, `get`, `save`, `update`, & `revert` actions read/write form html & json files. | |
15 | * 2. **_Using_ forms:** | |
16 | * The `prefill` and `submit` actions are used for preparing forms and processing submissions. | |
17 | * | |
18 | * @see https://lab.civicrm.org/extensions/afform | |
aa998597 | 19 | * @searchable none |
7422a230 | 20 | * @package Civi\Api4 |
7422a230 | 21 | */ |
c847b30c | 22 | class Afform extends Generic\AbstractEntity { |
aff08e16 TO |
23 | |
24 | /** | |
c847b30c CW |
25 | * @param bool $checkPermissions |
26 | * @return Action\Afform\Get | |
aff08e16 | 27 | */ |
c847b30c CW |
28 | public static function get($checkPermissions = TRUE) { |
29 | return (new Action\Afform\Get('Afform', __FUNCTION__)) | |
30 | ->setCheckPermissions($checkPermissions); | |
aff08e16 TO |
31 | } |
32 | ||
28b4ace4 | 33 | /** |
c847b30c CW |
34 | * @param bool $checkPermissions |
35 | * @return Action\Afform\Create | |
28b4ace4 | 36 | */ |
c847b30c CW |
37 | public static function create($checkPermissions = TRUE) { |
38 | return (new Action\Afform\Create('Afform', __FUNCTION__)) | |
39 | ->setCheckPermissions($checkPermissions); | |
28b4ace4 CW |
40 | } |
41 | ||
42 | /** | |
c847b30c CW |
43 | * @param bool $checkPermissions |
44 | * @return Action\Afform\Update | |
28b4ace4 | 45 | */ |
c847b30c | 46 | public static function update($checkPermissions = TRUE) { |
29ab318b | 47 | return (new Action\Afform\Update('Afform', __FUNCTION__)) |
c847b30c | 48 | ->setCheckPermissions($checkPermissions); |
28b4ace4 CW |
49 | } |
50 | ||
51 | /** | |
c847b30c CW |
52 | * @param bool $checkPermissions |
53 | * @return Action\Afform\Save | |
28b4ace4 | 54 | */ |
c847b30c | 55 | public static function save($checkPermissions = TRUE) { |
29ab318b | 56 | return (new Action\Afform\Save('Afform', __FUNCTION__)) |
c847b30c | 57 | ->setCheckPermissions($checkPermissions); |
28b4ace4 CW |
58 | } |
59 | ||
5c80fca4 TO |
60 | /** |
61 | * @param bool $checkPermissions | |
62 | * @return Action\Afform\Convert | |
63 | */ | |
64 | public static function convert($checkPermissions = TRUE) { | |
65 | return (new Action\Afform\Convert('Afform', __FUNCTION__)) | |
66 | ->setCheckPermissions($checkPermissions); | |
67 | } | |
68 | ||
28b4ace4 | 69 | /** |
c847b30c CW |
70 | * @param bool $checkPermissions |
71 | * @return Action\Afform\Prefill | |
28b4ace4 | 72 | */ |
c847b30c CW |
73 | public static function prefill($checkPermissions = TRUE) { |
74 | return (new Action\Afform\Prefill('Afform', __FUNCTION__)) | |
75 | ->setCheckPermissions($checkPermissions); | |
28b4ace4 CW |
76 | } |
77 | ||
78 | /** | |
c847b30c CW |
79 | * @param bool $checkPermissions |
80 | * @return Action\Afform\Submit | |
28b4ace4 | 81 | */ |
c847b30c CW |
82 | public static function submit($checkPermissions = TRUE) { |
83 | return (new Action\Afform\Submit('Afform', __FUNCTION__)) | |
84 | ->setCheckPermissions($checkPermissions); | |
28b4ace4 CW |
85 | } |
86 | ||
9d85626b CW |
87 | /** |
88 | * @param bool $checkPermissions | |
89 | * @return Action\Afform\SubmitFile | |
90 | */ | |
91 | public static function submitFile($checkPermissions = TRUE) { | |
92 | return (new Action\Afform\SubmitFile('Afform', __FUNCTION__)) | |
93 | ->setCheckPermissions($checkPermissions); | |
94 | } | |
95 | ||
db393580 CW |
96 | /** |
97 | * @param bool $checkPermissions | |
98 | * @return Action\Afform\GetOptions | |
99 | */ | |
100 | public static function getOptions($checkPermissions = TRUE) { | |
101 | return (new Action\Afform\GetOptions('Afform', __FUNCTION__)) | |
102 | ->setCheckPermissions($checkPermissions); | |
103 | } | |
104 | ||
aff08e16 | 105 | /** |
c847b30c | 106 | * @param bool $checkPermissions |
cc9b2a95 | 107 | * @return Action\Afform\Revert |
aff08e16 | 108 | */ |
c847b30c | 109 | public static function revert($checkPermissions = TRUE) { |
cc9b2a95 CW |
110 | return (new Action\Afform\Revert('Afform', __FUNCTION__)) |
111 | ->setCheckPermissions($checkPermissions); | |
aff08e16 TO |
112 | } |
113 | ||
c847b30c CW |
114 | /** |
115 | * @param bool $checkPermissions | |
116 | * @return Generic\BasicGetFieldsAction | |
117 | */ | |
118 | public static function getFields($checkPermissions = TRUE) { | |
dc36dc4d | 119 | return (new Generic\BasicGetFieldsAction('Afform', __FUNCTION__, function(BasicGetFieldsAction $self) { |
10fd70a3 | 120 | $fields = [ |
15b11f47 CW |
121 | [ |
122 | 'name' => 'name', | |
123 | ], | |
9e58ceed CW |
124 | [ |
125 | 'name' => 'type', | |
8031eb8e | 126 | 'pseudoconstant' => ['optionGroupName' => 'afform_type'], |
9e58ceed | 127 | ], |
15b11f47 CW |
128 | [ |
129 | 'name' => 'requires', | |
d625938f | 130 | 'data_type' => 'Array', |
15b11f47 | 131 | ], |
e1aca853 | 132 | [ |
fa8dc3f2 CW |
133 | 'name' => 'entity_type', |
134 | 'description' => 'Block used for this entity type', | |
e1aca853 CW |
135 | ], |
136 | [ | |
fa8dc3f2 CW |
137 | 'name' => 'join_entity', |
138 | 'description' => 'Used for blocks that join a sub-entity (e.g. Emails for a Contact)', | |
e1aca853 | 139 | ], |
15b11f47 CW |
140 | [ |
141 | 'name' => 'title', | |
28b4ace4 | 142 | 'required' => $self->getAction() === 'create', |
15b11f47 CW |
143 | ], |
144 | [ | |
145 | 'name' => 'description', | |
146 | ], | |
1887d8bd TO |
147 | [ |
148 | 'name' => 'is_dashlet', | |
149 | 'data_type' => 'Boolean', | |
150 | ], | |
15b11f47 CW |
151 | [ |
152 | 'name' => 'is_public', | |
153 | 'data_type' => 'Boolean', | |
154 | ], | |
053ab2a5 TO |
155 | [ |
156 | 'name' => 'is_token', | |
157 | 'data_type' => 'Boolean', | |
15b11f47 | 158 | ], |
c63f20d3 CW |
159 | [ |
160 | 'name' => 'contact_summary', | |
161 | 'data_type' => 'String', | |
eee24dde CW |
162 | 'options' => [ |
163 | 'block' => ts('Contact Summary Block'), | |
164 | 'tab' => ts('Contact Summary Tab'), | |
165 | ], | |
c63f20d3 | 166 | ], |
34c92b2c CW |
167 | [ |
168 | 'name' => 'icon', | |
169 | 'description' => 'Icon shown in the contact summary tab', | |
170 | ], | |
15b11f47 CW |
171 | [ |
172 | 'name' => 'server_route', | |
173 | ], | |
17535d7f TO |
174 | [ |
175 | 'name' => 'permission', | |
176 | ], | |
b6e13973 SL |
177 | [ |
178 | 'name' => 'redirect', | |
179 | ], | |
e6772fc6 CW |
180 | [ |
181 | 'name' => 'create_submission', | |
182 | 'data_type' => 'Boolean', | |
183 | ], | |
7b9f8bdc CW |
184 | [ |
185 | 'name' => 'navigation', | |
186 | 'data_type' => 'Array', | |
187 | 'description' => 'Insert into navigation menu {parent: string, label: string, weight: int}', | |
188 | ], | |
15b11f47 CW |
189 | [ |
190 | 'name' => 'layout', | |
d625938f | 191 | 'data_type' => 'Array', |
fa8dc3f2 | 192 | 'description' => 'HTML form layout; format is controlled by layoutFormat param', |
15b11f47 CW |
193 | ], |
194 | ]; | |
c63f20d3 | 195 | // Calculated fields returned by get action |
10fd70a3 | 196 | if ($self->getAction() === 'get') { |
25f2b36b CW |
197 | $fields[] = [ |
198 | 'name' => 'module_name', | |
60a62215 | 199 | 'type' => 'Extra', |
a0e733f3 | 200 | 'readonly' => TRUE, |
25f2b36b CW |
201 | ]; |
202 | $fields[] = [ | |
203 | 'name' => 'directive_name', | |
60a62215 | 204 | 'type' => 'Extra', |
a0e733f3 | 205 | 'readonly' => TRUE, |
25f2b36b | 206 | ]; |
10fd70a3 TO |
207 | $fields[] = [ |
208 | 'name' => 'has_local', | |
60a62215 | 209 | 'type' => 'Extra', |
d625938f | 210 | 'data_type' => 'Boolean', |
dc36dc4d | 211 | 'description' => 'Whether a local copy is saved on site', |
a0e733f3 | 212 | 'readonly' => TRUE, |
10fd70a3 TO |
213 | ]; |
214 | $fields[] = [ | |
2d4bfef1 | 215 | 'name' => 'has_base', |
60a62215 | 216 | 'type' => 'Extra', |
d625938f | 217 | 'data_type' => 'Boolean', |
dc36dc4d | 218 | 'description' => 'Is provided by an extension', |
a0e733f3 | 219 | 'readonly' => TRUE, |
10fd70a3 | 220 | ]; |
dc36dc4d CW |
221 | $fields[] = [ |
222 | 'name' => 'base_module', | |
223 | 'type' => 'Extra', | |
224 | 'data_type' => 'String', | |
225 | 'description' => 'Name of extension which provides this form', | |
226 | 'readonly' => TRUE, | |
8031eb8e | 227 | 'pseudoconstant' => ['callback' => ['CRM_Core_PseudoConstant', 'getExtensions']], |
dc36dc4d | 228 | ]; |
b076c308 CW |
229 | $fields[] = [ |
230 | 'name' => 'search_displays', | |
231 | 'type' => 'Extra', | |
232 | 'data_type' => 'Array', | |
233 | 'readonly' => TRUE, | |
234 | 'description' => 'Embedded search displays, formatted like ["search-name.display-name"]', | |
235 | ]; | |
10fd70a3 TO |
236 | } |
237 | ||
238 | return $fields; | |
c847b30c | 239 | }))->setCheckPermissions($checkPermissions); |
15b11f47 CW |
240 | } |
241 | ||
aff08e16 TO |
242 | /** |
243 | * @return array | |
244 | */ | |
245 | public static function permissions() { | |
246 | return [ | |
92d6b3d4 CW |
247 | 'meta' => ['access CiviCRM'], |
248 | 'default' => [['administer CiviCRM', 'administer afform']], | |
48be26b0 CW |
249 | // These all check form-level permissions |
250 | 'get' => [], | |
db393580 | 251 | 'getOptions' => [], |
3fe34185 CW |
252 | 'prefill' => [], |
253 | 'submit' => [], | |
9d85626b | 254 | 'submitFile' => [], |
aff08e16 TO |
255 | ]; |
256 | } | |
7422a230 | 257 | |
482a26e2 CW |
258 | /** |
259 | * @inheritDoc | |
260 | */ | |
261 | public static function getInfo() { | |
262 | $info = parent::getInfo(); | |
b675a457 | 263 | $info['primary_key'] = ['name']; |
482a26e2 CW |
264 | return $info; |
265 | } | |
266 | ||
7422a230 | 267 | } |