Clarify docblock
[civicrm-core.git] / ext / afform / core / Civi / Api4 / Afform.php
CommitLineData
7422a230
TO
1<?php
2
3namespace Civi\Api4;
4
f3062b8c
TO
5use Civi\Api4\Generic\AbstractEntity;
6use Civi\Api4\Generic\BasicBatchAction;
15b11f47 7use Civi\Api4\Generic\BasicGetFieldsAction;
7422a230
TO
8
9/**
10 * Class Afform
11 * @package Civi\Api4
7422a230 12 */
f3062b8c 13class Afform extends AbstractEntity {
aff08e16
TO
14
15 /**
11e724f0 16 * @return \Civi\Api4\Action\Afform\Get
aff08e16
TO
17 */
18 public static function get() {
11e724f0 19 return new \Civi\Api4\Action\Afform\Get('Afform', __FUNCTION__);
aff08e16
TO
20 }
21
22 /**
0770b5ed 23 * @return \Civi\Api4\Generic\BasicBatchAction
aff08e16
TO
24 */
25 public static function revert() {
f3062b8c
TO
26 return new BasicBatchAction('Afform', __FUNCTION__, ['name'], function($item, BasicBatchAction $action) {
27 $scanner = \Civi::service('afform_scanner');
28 $files = [
29 \CRM_Afform_AfformScanner::METADATA_FILE,
0770b5ed 30 \CRM_Afform_AfformScanner::LAYOUT_FILE,
f3062b8c
TO
31 ];
32
33 foreach ($files as $file) {
34 $metaPath = $scanner->createSiteLocalPath($item['name'], $file);
35 if (file_exists($metaPath)) {
36 if (!@unlink($metaPath)) {
37 throw new \API_Exception("Failed to remove afform overrides in $file");
38 }
39 }
40 }
41
42 // We may have changed list of files covered by the cache.
74f862e4 43 _afform_clear();
f3062b8c
TO
44
45 // FIXME if `server_route` changes, then flush the menu cache.
46 // FIXME if asset-caching is enabled, then flush the asset cache
47
48 return $item;
49 });
aff08e16
TO
50 }
51
52 /**
11e724f0 53 * @return \Civi\Api4\Action\Afform\Update
aff08e16
TO
54 */
55 public static function update() {
11e724f0 56 return new \Civi\Api4\Action\Afform\Update('Afform', __FUNCTION__, 'name');
f3062b8c 57 }
aff08e16 58
3fe34185
CW
59 /**
60 * @return \Civi\Api4\Action\Afform\Prefill
61 */
62 public static function prefill() {
63 return new \Civi\Api4\Action\Afform\Prefill('Afform', __FUNCTION__);
64 }
65
66 /**
67 * @return \Civi\Api4\Action\Afform\Submit
68 */
69 public static function submit() {
70 return new \Civi\Api4\Action\Afform\Submit('Afform', __FUNCTION__);
71 }
72
15b11f47
CW
73 public static function getFields() {
74 return new BasicGetFieldsAction('Afform', __FUNCTION__, function() {
75 return [
76 [
77 'name' => 'name',
78 ],
79 [
80 'name' => 'requires',
81 ],
82 [
83 'name' => 'title',
84 ],
85 [
86 'name' => 'description',
87 ],
88 [
89 'name' => 'is_public',
90 'data_type' => 'Boolean',
91 ],
92 [
93 'name' => 'server_route',
94 ],
95 [
96 'name' => 'layout',
97 ],
98 ];
99 });
100 }
101
aff08e16
TO
102 /**
103 * @return array
104 */
105 public static function permissions() {
106 return [
107 "meta" => ["access CiviCRM"],
108 "default" => ["administer CiviCRM"],
3fe34185
CW
109 'prefill' => [],
110 'submit' => [],
aff08e16
TO
111 ];
112 }
7422a230
TO
113
114}