5 use Civi\Api4\Generic\BasicBatchAction
;
6 use Civi\Api4\Generic\BasicGetFieldsAction
;
9 * User-configurable forms.
11 * Afform stands for *The Affable Administrative Angular Form Framework*.
13 * This API provides actions for
14 * 1. **_Managing_ forms:**
15 * The `create`, `get`, `save`, `update`, & `revert` actions read/write form html & json files.
16 * 2. **_Using_ forms:**
17 * The `prefill` and `submit` actions are used for preparing forms and processing submissions.
19 * @see https://lab.civicrm.org/extensions/afform
23 class Afform
extends Generic\AbstractEntity
{
26 * @param bool $checkPermissions
27 * @return Action\Afform\Get
29 public static function get($checkPermissions = TRUE) {
30 return (new Action\Afform\
Get('Afform', __FUNCTION__
))
31 ->setCheckPermissions($checkPermissions);
35 * @param bool $checkPermissions
36 * @return Action\Afform\Create
38 public static function create($checkPermissions = TRUE) {
39 return (new Action\Afform\
Create('Afform', __FUNCTION__
))
40 ->setCheckPermissions($checkPermissions);
44 * @param bool $checkPermissions
45 * @return Action\Afform\Update
47 public static function update($checkPermissions = TRUE) {
48 return (new Action\Afform\
Update('Afform', __FUNCTION__
))
49 ->setCheckPermissions($checkPermissions);
53 * @param bool $checkPermissions
54 * @return Action\Afform\Save
56 public static function save($checkPermissions = TRUE) {
57 return (new Action\Afform\
Save('Afform', __FUNCTION__
))
58 ->setCheckPermissions($checkPermissions);
62 * @param bool $checkPermissions
63 * @return Action\Afform\Convert
65 public static function convert($checkPermissions = TRUE) {
66 return (new Action\Afform\
Convert('Afform', __FUNCTION__
))
67 ->setCheckPermissions($checkPermissions);
71 * @param bool $checkPermissions
72 * @return Action\Afform\Prefill
74 public static function prefill($checkPermissions = TRUE) {
75 return (new Action\Afform\
Prefill('Afform', __FUNCTION__
))
76 ->setCheckPermissions($checkPermissions);
80 * @param bool $checkPermissions
81 * @return Action\Afform\Submit
83 public static function submit($checkPermissions = TRUE) {
84 return (new Action\Afform\
Submit('Afform', __FUNCTION__
))
85 ->setCheckPermissions($checkPermissions);
89 * @param bool $checkPermissions
90 * @return Action\Afform\SubmitFile
92 public static function submitFile($checkPermissions = TRUE) {
93 return (new Action\Afform\
SubmitFile('Afform', __FUNCTION__
))
94 ->setCheckPermissions($checkPermissions);
98 * @param bool $checkPermissions
99 * @return Action\Afform\GetOptions
101 public static function getOptions($checkPermissions = TRUE) {
102 return (new Action\Afform\
GetOptions('Afform', __FUNCTION__
))
103 ->setCheckPermissions($checkPermissions);
107 * @param bool $checkPermissions
108 * @return Generic\BasicBatchAction
110 public static function revert($checkPermissions = TRUE) {
111 return (new BasicBatchAction('Afform', __FUNCTION__
, function($item, BasicBatchAction
$action) {
112 $scanner = \Civi
::service('afform_scanner');
114 \CRM_Afform_AfformScanner
::METADATA_FILE
,
115 \CRM_Afform_AfformScanner
::LAYOUT_FILE
,
118 foreach ($files as $file) {
119 $metaPath = $scanner->createSiteLocalPath($item['name'], $file);
120 if (file_exists($metaPath)) {
121 if (!@unlink
($metaPath)) {
122 throw new \
API_Exception("Failed to remove afform overrides in $file");
127 // We may have changed list of files covered by the cache.
130 // FIXME if `server_route` changes, then flush the menu cache.
131 // FIXME if asset-caching is enabled, then flush the asset cache
134 }))->setCheckPermissions($checkPermissions);
138 * @param bool $checkPermissions
139 * @return Generic\BasicGetFieldsAction
141 public static function getFields($checkPermissions = TRUE) {
142 return (new Generic\
BasicGetFieldsAction('Afform', __FUNCTION__
, function(BasicGetFieldsAction
$self) {
149 'options' => $self->pseudoconstantOptions('afform_type'),
150 'suffixes' => ['id', 'name', 'label', 'icon'],
153 'name' => 'requires',
154 'data_type' => 'Array',
157 'name' => 'entity_type',
158 'description' => 'Block used for this entity type',
161 'name' => 'join_entity',
162 'description' => 'Used for blocks that join a sub-entity (e.g. Emails for a Contact)',
166 'required' => $self->getAction() === 'create',
169 'name' => 'description',
172 'name' => 'is_dashlet',
173 'data_type' => 'Boolean',
176 'name' => 'is_public',
177 'data_type' => 'Boolean',
180 'name' => 'is_token',
181 'data_type' => 'Boolean',
184 'name' => 'contact_summary',
185 'data_type' => 'String',
187 'block' => ts('Contact Summary Block'),
188 'tab' => ts('Contact Summary Tab'),
192 'name' => 'server_route',
195 'name' => 'permission',
198 'name' => 'redirect',
201 'name' => 'create_submission',
202 'data_type' => 'Boolean',
206 'data_type' => 'Array',
207 'description' => 'HTML form layout; format is controlled by layoutFormat param',
210 // Calculated fields returned by get action
211 if ($self->getAction() === 'get') {
213 'name' => 'module_name',
218 'name' => 'directive_name',
223 'name' => 'has_local',
225 'data_type' => 'Boolean',
226 'description' => 'Whether a local copy is saved on site',
230 'name' => 'has_base',
232 'data_type' => 'Boolean',
233 'description' => 'Is provided by an extension',
237 'name' => 'base_module',
239 'data_type' => 'String',
240 'description' => 'Name of extension which provides this form',
242 'options' => $self->getLoadOptions() ? \CRM_Core_PseudoConstant
::getExtensions() : TRUE,
245 'name' => 'search_displays',
247 'data_type' => 'Array',
249 'description' => 'Embedded search displays, formatted like ["search-name.display-name"]',
254 }))->setCheckPermissions($checkPermissions);
260 public static function permissions() {
262 "meta" => ["access CiviCRM"],
263 "default" => ["administer CiviCRM"],
264 // These all check form-level permissions
276 public static function getInfo() {
277 $info = parent
::getInfo();
278 $info['primary_key'] = ['name'];