diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index 917922806db6..90278877f8de 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -27,7 +27,7 @@ function civicrm_api3_generic_getList($apiRequest) { $meta = civicrm_api3_generic_getfields(['action' => 'get'] + $apiRequest, FALSE); // If the user types an integer into the search - $forceIdSearch = empty($request['id']) && !empty($request['input']) && CRM_Utils_Rule::positiveInteger($request['input']); + $forceIdSearch = empty($request['id']) && !empty($request['input']) && !empty($meta['id']) && CRM_Utils_Rule::positiveInteger($request['input']); // Add an extra page of results for the record with an exact id match if ($forceIdSearch) { $request['page_num'] = ($request['page_num'] ?? 1) - 1; @@ -230,7 +230,7 @@ function _civicrm_api3_generic_getlist_output($result, $request, $entity, $field } } } - }; + } if (!empty($request['image_field'])) { $data['image'] = $row[$request['image_field']] ?? ''; } diff --git a/ext/afform/core/api/v3/Afform.php b/ext/afform/core/api/v3/Afform.php index cc2ca96ca225..3ed305531542 100644 --- a/ext/afform/core/api/v3/Afform.php +++ b/ext/afform/core/api/v3/Afform.php @@ -25,14 +25,14 @@ function civicrm_api3_afform_get($params) { $result[$name] = array_merge($record, $info); } - $filterableFields = ['name', 'module_name', 'directive_name', 'server_route', 'type', 'description', 'title']; - return _civicrm_api3_basic_array_get('Afform', $params, $result, 'name', $filterableFields); + $allFields = []; + _civicrm_api3_afform_get_spec($allFields); + return _civicrm_api3_basic_array_get('Afform', $params, $result, 'name', array_keys($allFields)); } function _civicrm_api3_afform_get_spec(&$fields) { $fields['name'] = [ 'title' => 'Name', - 'api.aliases' => ['id'], 'type' => CRM_Utils_Type::T_STRING, ]; $fields['title'] = [ @@ -68,3 +68,47 @@ function _civicrm_api3_afform_get_spec(&$fields) { 'type' => CRM_Utils_Type::T_BOOLEAN, ]; } + +/** + * Augment parameters for Afform entityRef list. + * + * @see _civicrm_api3_generic_getlist_params + * + * @param array $request + * API request. + */ +function _civicrm_api3_afform_getlist_params(&$request) { + $fieldsToReturn = ['name', 'title', 'type', 'description']; + $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra'])); + $request['params']['options']['sort'] = 'activity_date_time DESC'; +} + +/** + * Get output for activity list. + * + * @see _civicrm_api3_generic_getlist_output + * + * @param array $result + * @param array $request + * + * @return array + */ +function _civicrm_api3_afform_getlist_output($result, $request) { + $output = []; + if (!empty($result['values'])) { + $icons = CRM_Core_OptionGroup::values('afform_type', FALSE, FALSE, FALSE, NULL, 'icon', FALSE); + foreach ($result['values'] as $row) { + $data = [ + 'id' => $row[$request['id_field']], + 'label' => $row[$request['label_field']], + 'description' => [], + 'icon' => $icons[$row['type']], + ]; + if (!empty($row['description'])) { + $data['description'][] = $row['description']; + } + $output[] = $data; + } + } + return $output; +} diff --git a/js/Common.js b/js/Common.js index 63db35419386..5c68227c3784 100644 --- a/js/Common.js +++ b/js/Common.js @@ -741,6 +741,7 @@ if (!CRM.vars) CRM.vars = {}; } markup += '
' + (row.color ? ' ' : '') + + (row.icon ? ' ' : '') + _.escape((row.prefix !== undefined ? row.prefix + ' ' : '') + row.label + (row.suffix !== undefined ? ' ' + row.suffix : '')) + '
' + '
';