5 use Civi\Api4\Generic\BasicGetFieldsAction
;
8 * User-configurable forms.
10 * Afform stands for *The Affable Administrative Angular Form Framework*.
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.
18 * @see https://lab.civicrm.org/extensions/afform
22 class Afform
extends Generic\AbstractEntity
{
25 * @param bool $checkPermissions
26 * @return Action\Afform\Get
28 public static function get($checkPermissions = TRUE) {
29 return (new Action\Afform\
Get('Afform', __FUNCTION__
))
30 ->setCheckPermissions($checkPermissions);
34 * @param bool $checkPermissions
35 * @return Action\Afform\Create
37 public static function create($checkPermissions = TRUE) {
38 return (new Action\Afform\
Create('Afform', __FUNCTION__
))
39 ->setCheckPermissions($checkPermissions);
43 * @param bool $checkPermissions
44 * @return Action\Afform\Update
46 public static function update($checkPermissions = TRUE) {
47 return (new Action\Afform\
Update('Afform', __FUNCTION__
))
48 ->setCheckPermissions($checkPermissions);
52 * @param bool $checkPermissions
53 * @return Action\Afform\Save
55 public static function save($checkPermissions = TRUE) {
56 return (new Action\Afform\
Save('Afform', __FUNCTION__
))
57 ->setCheckPermissions($checkPermissions);
61 * @param bool $checkPermissions
62 * @return Action\Afform\Convert
64 public static function convert($checkPermissions = TRUE) {
65 return (new Action\Afform\
Convert('Afform', __FUNCTION__
))
66 ->setCheckPermissions($checkPermissions);
70 * @param bool $checkPermissions
71 * @return Action\Afform\Prefill
73 public static function prefill($checkPermissions = TRUE) {
74 return (new Action\Afform\
Prefill('Afform', __FUNCTION__
))
75 ->setCheckPermissions($checkPermissions);
79 * @param bool $checkPermissions
80 * @return Action\Afform\Submit
82 public static function submit($checkPermissions = TRUE) {
83 return (new Action\Afform\
Submit('Afform', __FUNCTION__
))
84 ->setCheckPermissions($checkPermissions);
88 * @param bool $checkPermissions
89 * @return Action\Afform\SubmitFile
91 public static function submitFile($checkPermissions = TRUE) {
92 return (new Action\Afform\
SubmitFile('Afform', __FUNCTION__
))
93 ->setCheckPermissions($checkPermissions);
97 * @param bool $checkPermissions
98 * @return Action\Afform\GetOptions
100 public static function getOptions($checkPermissions = TRUE) {
101 return (new Action\Afform\
GetOptions('Afform', __FUNCTION__
))
102 ->setCheckPermissions($checkPermissions);
106 * @param bool $checkPermissions
107 * @return Action\Afform\Revert
109 public static function revert($checkPermissions = TRUE) {
110 return (new Action\Afform\
Revert('Afform', __FUNCTION__
))
111 ->setCheckPermissions($checkPermissions);
115 * @param bool $checkPermissions
116 * @return Generic\BasicGetFieldsAction
118 public static function getFields($checkPermissions = TRUE) {
119 return (new Generic\
BasicGetFieldsAction('Afform', __FUNCTION__
, function(BasicGetFieldsAction
$self) {
126 'options' => $self->pseudoconstantOptions('afform_type'),
127 'suffixes' => ['id', 'name', 'label', 'icon'],
130 'name' => 'requires',
131 'data_type' => 'Array',
134 'name' => 'entity_type',
135 'description' => 'Block used for this entity type',
138 'name' => 'join_entity',
139 'description' => 'Used for blocks that join a sub-entity (e.g. Emails for a Contact)',
143 'required' => $self->getAction() === 'create',
146 'name' => 'description',
149 'name' => 'is_dashlet',
150 'data_type' => 'Boolean',
153 'name' => 'is_public',
154 'data_type' => 'Boolean',
157 'name' => 'is_token',
158 'data_type' => 'Boolean',
161 'name' => 'contact_summary',
162 'data_type' => 'String',
164 'block' => ts('Contact Summary Block'),
165 'tab' => ts('Contact Summary Tab'),
170 'description' => 'Icon shown in the contact summary tab',
173 'name' => 'server_route',
176 'name' => 'permission',
179 'name' => 'redirect',
182 'name' => 'create_submission',
183 'data_type' => 'Boolean',
187 'data_type' => 'Array',
188 'description' => 'HTML form layout; format is controlled by layoutFormat param',
191 // Calculated fields returned by get action
192 if ($self->getAction() === 'get') {
194 'name' => 'module_name',
199 'name' => 'directive_name',
204 'name' => 'has_local',
206 'data_type' => 'Boolean',
207 'description' => 'Whether a local copy is saved on site',
211 'name' => 'has_base',
213 'data_type' => 'Boolean',
214 'description' => 'Is provided by an extension',
218 'name' => 'base_module',
220 'data_type' => 'String',
221 'description' => 'Name of extension which provides this form',
223 'options' => $self->getLoadOptions() ? \CRM_Core_PseudoConstant
::getExtensions() : TRUE,
226 'name' => 'search_displays',
228 'data_type' => 'Array',
230 'description' => 'Embedded search displays, formatted like ["search-name.display-name"]',
235 }))->setCheckPermissions($checkPermissions);
241 public static function permissions() {
243 'meta' => ['access CiviCRM'],
244 'default' => [['administer CiviCRM', 'administer afform']],
245 // These all check form-level permissions
257 public static function getInfo() {
258 $info = parent
::getInfo();
259 $info['primary_key'] = ['name'];