['key' => 'organization_name', 'value' => ts('Employer name'), 'type' => 'text', 'condition' => ['contact_type' => 'Individual']],
['key' => 'gender_id', 'value' => ts('Gender'), 'condition' => ['contact_type' => 'Individual']],
['key' => 'is_deceased', 'value' => ts('Deceased'), 'condition' => ['contact_type' => 'Individual']],
- ['key' => 'contact_id', 'value' => ts('Contact ID'), 'type' => 'text'],
['key' => 'external_identifier', 'value' => ts('External ID'), 'type' => 'text'],
['key' => 'source', 'value' => ts('Contact Source'), 'type' => 'text'],
];
$request = $apiRequest['params'];
$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']);
+ // Add an extra page of results for the record with an exact id match
+ if ($forceIdSearch) {
+ $request['page_num'] = ($request['page_num'] ?? 1) - 1;
+ if (empty($request['page_num'])) {
+ $request['id'] = $request['input'];
+ unset($request['input']);
+ }
+ }
+
// Hey api, would you like to provide default values?
$fnName = "_civicrm_api3_{$entity}_getlist_defaults";
$defaults = function_exists($fnName) ? $fnName($request) : [];
$output = ['page_num' => $request['page_num']];
+ if ($forceIdSearch) {
+ $output['page_num']++;
+ // When returning the single record matching id
+ if (empty($request['page_num'])) {
+ $output['more_results'] = TRUE;
+ foreach ($values as $i => $value) {
+ $description = ts('ID: %1', [1 => $value['id']]);
+ $values[$i]['description'] = array_merge([$description], $value['description'] ?? []);
+ }
+ }
+ }
// Limit is set for searching but not fetching by id
- if (!empty($request['params']['options']['limit'])) {
+ elseif (!empty($request['params']['options']['limit'])) {
// If we have an extra result then this is not the last page
$last = $request['params']['options']['limit'] - 1;
$output['more_results'] = isset($values[$last]);