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 | ||
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. | |
43 | $scanner->clear(); | |
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 | |
15b11f47 CW |
59 | public static function getFields() { |
60 | return new BasicGetFieldsAction('Afform', __FUNCTION__, function() { | |
61 | return [ | |
62 | [ | |
63 | 'name' => 'name', | |
64 | ], | |
65 | [ | |
66 | 'name' => 'requires', | |
67 | ], | |
68 | [ | |
69 | 'name' => 'title', | |
70 | ], | |
71 | [ | |
72 | 'name' => 'description', | |
73 | ], | |
74 | [ | |
75 | 'name' => 'is_public', | |
76 | 'data_type' => 'Boolean', | |
77 | ], | |
78 | [ | |
79 | 'name' => 'server_route', | |
80 | ], | |
81 | [ | |
82 | 'name' => 'layout', | |
83 | ], | |
84 | ]; | |
85 | }); | |
86 | } | |
87 | ||
aff08e16 TO |
88 | /** |
89 | * @return array | |
90 | */ | |
91 | public static function permissions() { | |
92 | return [ | |
93 | "meta" => ["access CiviCRM"], | |
94 | "default" => ["administer CiviCRM"], | |
95 | ]; | |
96 | } | |
7422a230 TO |
97 | |
98 | } |