Autocomplete - Fix incorrect matching on id instead of value
authorcolemanw <coleman@civicrm.org>
Thu, 23 Nov 2023 21:44:51 +0000 (16:44 -0500)
committercolemanw <coleman@civicrm.org>
Fri, 24 Nov 2023 14:47:28 +0000 (09:47 -0500)
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.

Civi/Api4/Event/Subscriber/AutocompleteFieldSubscriber.php
Civi/Api4/Generic/AutocompleteAction.php

index 3943c2a29905b44902277cc1d66223c597185e7f..05d955740f141f429da7f7fe859e1a4c39957a12 100644 (file)
@@ -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);
         }
index fe87afe8d2996f3078493d1a5c665e8161a27792..d50c62f9f363b48b87e7e5d88d56efcb4ef0d77a 100644 (file)
@@ -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');