Autocomplete - Search by id if entity has no title or label
authorcolemanw <coleman@civicrm.org>
Thu, 16 Nov 2023 20:31:35 +0000 (15:31 -0500)
committercolemanw <coleman@civicrm.org>
Fri, 17 Nov 2023 00:23:22 +0000 (19:23 -0500)
ext/search_kit/Civi/Api4/Event/Subscriber/DefaultDisplaySubscriber.php

index 03649969ba12b98386ddeadbce72439b5fb491dd..54cd5ce2cffe202e7d5aa2091008f19041954d2d 100644 (file)
@@ -59,10 +59,9 @@ class DefaultDisplaySubscriber extends \Civi\Core\Service\AutoService implements
       throw new \CRM_Core_Exception("Entity name is required to get autocomplete default display.");
     }
     $idField = CoreUtil::getIdFieldName($entityName);
-    $searchFields = CoreUtil::getSearchFields($entityName);
-    if (!$searchFields) {
-      throw new \CRM_Core_Exception("Entity $entityName has no default label field.");
-    }
+
+    // If there's no label field, fall back on id. That's a pretty lame autocomplete but better than nothing.
+    $searchFields = CoreUtil::getSearchFields($entityName) ?: [$idField];
 
     // Default sort order
     $e->display['settings']['sort'] = self::getDefaultSort($entityName);