From: Coleman Watts Date: Wed, 24 Feb 2021 13:36:43 +0000 (-0500) Subject: EntityRef - Fix merging api params when searching by id X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9610f30871a46b818e09fac2786bae39d819df80;p=civicrm-core.git EntityRef - Fix merging api params when searching by id --- diff --git a/api/v3/Generic/Getlist.php b/api/v3/Generic/Getlist.php index 58e8f18fbb..917922806d 100644 --- a/api/v3/Generic/Getlist.php +++ b/api/v3/Generic/Getlist.php @@ -153,26 +153,28 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request, $apiDefaults if ($request['input']) { $params[$request['search_field']] = ['LIKE' => ($request['add_wildcard'] ? '%' : '') . $request['input'] . '%']; } + $request['params'] += $params; + // When looking up a field e.g. displaying existing record if (!empty($request['id'])) { if (is_string($request['id']) && strpos($request['id'], ',')) { $request['id'] = explode(',', trim($request['id'], ', ')); } // Don't run into search limits when prefilling selection - $params['options']['limit'] = NULL; - unset($params['options']['offset'], $request['params']['options']['limit'], $request['params']['options']['offset']); - $params[$request['id_field']] = is_array($request['id']) ? ['IN' => $request['id']] : $request['id']; + $request['params']['options']['limit'] = NULL; + unset($request['params']['options']['offset']); + $request['params'][$request['id_field']] = is_array($request['id']) ? ['IN' => $request['id']] : $request['id']; + } + else { + $request['params']['options'] += [ + // Add pagination parameters + 'sort' => $request['label_field'], + // Adding one extra result allows us to see if there are any more + 'limit' => $resultsPerPage + 1, + // Because sql is zero-based + 'offset' => ($request['page_num'] - 1) * $resultsPerPage, + ]; } - $request['params'] += $params; - - $request['params']['options'] += [ - // Add pagination parameters - 'sort' => $request['label_field'], - // Adding one extra result allows us to see if there are any more - 'limit' => $resultsPerPage + 1, - // Because sql is zero-based - 'offset' => ($request['page_num'] - 1) * $resultsPerPage, - ]; } /**