From: colemanw Date: Thu, 23 Nov 2023 21:44:51 +0000 (-0500) Subject: Autocomplete - Fix incorrect matching on id instead of value X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2cd77ebf505e17776b53e33b5ae1d134b9a86edc;p=civicrm-core.git Autocomplete - Fix incorrect matching on id instead of value Backports https://github.com/civicrm/civicrm-core/pull/28283 Fixes https://lab.civicrm.org/dev/core/-/issues/4799 Custom fields of type Autocomplete-Select were incorrectly using the id of the optionValue. This fixes it to use the value, and also show the value in the autocomplete results. --- diff --git a/Civi/Api4/Event/Subscriber/AutocompleteFieldSubscriber.php b/Civi/Api4/Event/Subscriber/AutocompleteFieldSubscriber.php index 3943c2a299..05d955740f 100644 --- a/Civi/Api4/Event/Subscriber/AutocompleteFieldSubscriber.php +++ b/Civi/Api4/Event/Subscriber/AutocompleteFieldSubscriber.php @@ -67,6 +67,11 @@ class AutocompleteFieldSubscriber extends AutoService implements EventSubscriber $apiRequest->addFilter($key, $value); } + // Autocomplete for field with option values + if ($apiRequest->getEntityName() === 'OptionValue' && !empty($fieldSpec['custom_field_id'])) { + $apiRequest->setKey('value'); + } + if ($formType === 'qf') { $this->autocompleteProfilePermissions($apiRequest, $formName, $fieldSpec); } diff --git a/Civi/Api4/Generic/AutocompleteAction.php b/Civi/Api4/Generic/AutocompleteAction.php index fe87afe8d2..d50c62f9f3 100644 --- a/Civi/Api4/Generic/AutocompleteAction.php +++ b/Civi/Api4/Generic/AutocompleteAction.php @@ -285,6 +285,10 @@ class AutocompleteAction extends AbstractAction { */ private function getKeyField() { $entityName = $this->savedSearch['api_entity']; + // Temp hack for 5.67. Fixed in 5.68. See https://github.com/civicrm/civicrm-core/pull/28283 + if ($entityName === 'OptionValue' && $this->key === 'value') { + return 'value'; + } if ($this->key) { /** @var \CRM_Core_DAO $dao */ $dao = CoreUtil::getInfoItem($entityName, 'dao');