Afform.get - Fix copy-paste mistake
[civicrm-core.git] / ext / afform / api / v3 / Afform / Get.php
1 <?php
2 use CRM_Afform_ExtensionUtil as E;
3
4 /**
5 * Afform.Get API specification (optional)
6 * This is used for documentation and validation.
7 *
8 * @param array $spec description of fields supported by this API call
9 * @return void
10 * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
11 */
12 function _civicrm_api3_afform_get_spec(&$spec) {
13 $spec['name'] = array(
14 'name' => 'name',
15 'type' => CRM_Utils_Type::T_STRING,
16 'title' => ts('Form name'),
17 'description' => 'Form name',
18 'maxlength' => 128,
19 'size' => CRM_Utils_Type::HUGE,
20 );
21 $spec['description'] = array(
22 'name' => 'description',
23 'type' => CRM_Utils_Type::T_TEXT,
24 'title' => ts('Description'),
25 'description' => 'Description',
26 );
27
28 // FIXME: title, requires, layout, server_route, client_route
29 }
30
31 /**
32 * Afform.Get API
33 *
34 * @param array $params
35 * @return array API result descriptor
36 * @see civicrm_api3_create_success
37 * @see civicrm_api3_create_error
38 * @throws API_Exception
39 */
40 function civicrm_api3_afform_get($params) {
41 $scanner = new CRM_Afform_AfformScanner();
42 $converter = new CRM_Afform_ArrayHtml();
43 $records = [];
44
45 if (isset($params['name']) && is_string($params['name'])) {
46 $names = [$params['name']];
47 }
48 else {
49 $names = array_keys($scanner->findFilePaths());
50 }
51
52 foreach ($names as $name) {
53 $record = $scanner->getMeta($name);
54 $layout = $scanner->findFilePath($name, 'layout.html');
55 if ($layout) {
56 // FIXME check for file existence+substance+validity
57 $record['layout'] = $converter->convertHtmlToArray(file_get_contents($layout));
58 }
59 $records[$name] = $record;
60 }
61
62 return _civicrm_api3_basic_array_get('Afform', $params, $records, 'name', _afform_fields());
63 }