2 use CRM_Afform_ExtensionUtil
as E
;
5 * Afform.Get API specification (optional)
6 * This is used for documentation and validation.
8 * @param array $spec description of fields supported by this API call
10 * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
12 function _civicrm_api3_afform_get_spec(&$spec) {
13 $spec['name'] = array(
15 'type' => CRM_Utils_Type
::T_STRING
,
16 'title' => ts('Form name'),
17 'description' => 'Form name',
19 'size' => CRM_Utils_Type
::HUGE
,
21 $spec['description'] = array(
22 'name' => 'description',
23 'type' => CRM_Utils_Type
::T_TEXT
,
24 'title' => ts('Description'),
25 'description' => 'Description',
28 // FIXME: title, requires, layout, server_route, client_route
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
40 function civicrm_api3_afform_get($params) {
41 $scanner = new CRM_Afform_AfformScanner();
42 $converter = new CRM_Afform_ArrayHtml();
45 if (isset($params['name']) && is_string($params['name'])) {
46 $names = [$params['name']];
49 $names = array_keys($scanner->findFilePaths());
52 foreach ($names as $name) {
53 $record = $scanner->getMeta($name);
54 $layout = $scanner->findFilePath($name, 'layout.html');
56 // FIXME check for file existence+substance+validity
57 $record['layout'] = $converter->convertHtmlToArray(file_get_contents($layout));
59 $records[$name] = $record;
62 return _civicrm_api3_basic_array_get('Afform', $params, $records, 'name', _afform_fields());