Commit | Line | Data |
---|---|---|
7422a230 TO |
1 | <?php |
2 | ||
3 | namespace Civi\Api4; | |
4 | ||
f3062b8c TO |
5 | use Civi\Api4\Generic\AbstractEntity; |
6 | use Civi\Api4\Generic\BasicBatchAction; | |
15b11f47 | 7 | use Civi\Api4\Generic\BasicGetFieldsAction; |
7422a230 TO |
8 | |
9 | /** | |
10 | * Class Afform | |
11 | * @package Civi\Api4 | |
7422a230 | 12 | */ |
f3062b8c | 13 | class 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 | ||
28b4ace4 CW |
22 | /** |
23 | * @return \Civi\Api4\Action\Afform\Create | |
24 | */ | |
25 | public static function create() { | |
26 | return new \Civi\Api4\Action\Afform\Create('Afform', __FUNCTION__); | |
27 | } | |
28 | ||
29 | /** | |
30 | * @return \Civi\Api4\Action\Afform\Update | |
31 | */ | |
32 | public static function update() { | |
33 | return new \Civi\Api4\Action\Afform\Update('Afform', __FUNCTION__, 'name'); | |
34 | } | |
35 | ||
36 | /** | |
37 | * @return \Civi\Api4\Action\Afform\Save | |
38 | */ | |
39 | public static function save() { | |
40 | return new \Civi\Api4\Action\Afform\Save('Afform', __FUNCTION__, 'name'); | |
41 | } | |
42 | ||
43 | /** | |
44 | * @return \Civi\Api4\Action\Afform\Prefill | |
45 | */ | |
46 | public static function prefill() { | |
47 | return new \Civi\Api4\Action\Afform\Prefill('Afform', __FUNCTION__); | |
48 | } | |
49 | ||
50 | /** | |
51 | * @return \Civi\Api4\Action\Afform\Submit | |
52 | */ | |
53 | public static function submit() { | |
54 | return new \Civi\Api4\Action\Afform\Submit('Afform', __FUNCTION__); | |
55 | } | |
56 | ||
aff08e16 | 57 | /** |
0770b5ed | 58 | * @return \Civi\Api4\Generic\BasicBatchAction |
aff08e16 TO |
59 | */ |
60 | public static function revert() { | |
f3062b8c TO |
61 | return new BasicBatchAction('Afform', __FUNCTION__, ['name'], function($item, BasicBatchAction $action) { |
62 | $scanner = \Civi::service('afform_scanner'); | |
63 | $files = [ | |
64 | \CRM_Afform_AfformScanner::METADATA_FILE, | |
0770b5ed | 65 | \CRM_Afform_AfformScanner::LAYOUT_FILE, |
f3062b8c TO |
66 | ]; |
67 | ||
68 | foreach ($files as $file) { | |
69 | $metaPath = $scanner->createSiteLocalPath($item['name'], $file); | |
70 | if (file_exists($metaPath)) { | |
71 | if (!@unlink($metaPath)) { | |
72 | throw new \API_Exception("Failed to remove afform overrides in $file"); | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
77 | // We may have changed list of files covered by the cache. | |
74f862e4 | 78 | _afform_clear(); |
f3062b8c TO |
79 | |
80 | // FIXME if `server_route` changes, then flush the menu cache. | |
81 | // FIXME if asset-caching is enabled, then flush the asset cache | |
82 | ||
83 | return $item; | |
84 | }); | |
aff08e16 TO |
85 | } |
86 | ||
15b11f47 | 87 | public static function getFields() { |
28b4ace4 | 88 | return new BasicGetFieldsAction('Afform', __FUNCTION__, function($self) { |
10fd70a3 | 89 | $fields = [ |
15b11f47 CW |
90 | [ |
91 | 'name' => 'name', | |
92 | ], | |
93 | [ | |
94 | 'name' => 'requires', | |
95 | ], | |
e1aca853 CW |
96 | [ |
97 | 'name' => 'block', | |
98 | ], | |
99 | [ | |
100 | 'name' => 'extends', | |
101 | ], | |
15b11f47 CW |
102 | [ |
103 | 'name' => 'title', | |
28b4ace4 | 104 | 'required' => $self->getAction() === 'create', |
15b11f47 CW |
105 | ], |
106 | [ | |
107 | 'name' => 'description', | |
108 | ], | |
109 | [ | |
110 | 'name' => 'is_public', | |
111 | 'data_type' => 'Boolean', | |
112 | ], | |
e1aca853 CW |
113 | [ |
114 | 'name' => 'repeatable', | |
115 | 'data_type' => 'Boolean', | |
116 | ], | |
15b11f47 CW |
117 | [ |
118 | 'name' => 'server_route', | |
119 | ], | |
17535d7f TO |
120 | [ |
121 | 'name' => 'permission', | |
122 | ], | |
15b11f47 CW |
123 | [ |
124 | 'name' => 'layout', | |
125 | ], | |
126 | ]; | |
10fd70a3 TO |
127 | |
128 | if ($self->getAction() === 'get') { | |
129 | $fields[] = [ | |
130 | 'name' => 'has_local', | |
131 | ]; | |
132 | $fields[] = [ | |
2d4bfef1 | 133 | 'name' => 'has_base', |
10fd70a3 TO |
134 | ]; |
135 | } | |
136 | ||
137 | return $fields; | |
15b11f47 CW |
138 | }); |
139 | } | |
140 | ||
aff08e16 TO |
141 | /** |
142 | * @return array | |
143 | */ | |
144 | public static function permissions() { | |
145 | return [ | |
146 | "meta" => ["access CiviCRM"], | |
147 | "default" => ["administer CiviCRM"], | |
3fe34185 CW |
148 | 'prefill' => [], |
149 | 'submit' => [], | |
aff08e16 TO |
150 | ]; |
151 | } | |
7422a230 TO |
152 | |
153 | } |