Fix APIv4 autocompletes for dynamic entities
authorColeman Watts <coleman@civicrm.org>
Wed, 1 Feb 2023 18:40:27 +0000 (13:40 -0500)
committerColeman Watts <coleman@civicrm.org>
Wed, 1 Feb 2023 18:40:27 +0000 (13:40 -0500)
Ensures APIv4 autocompletes work with dynamic entities like Multi-Record custom groups & the ECK extension

Civi/API/Request.php
ext/search_kit/Civi/Api4/Event/Subscriber/DefaultDisplaySubscriber.php

index 62cd7605cdf6c9e1b15ae2c79362b91c347263b6..8b7a087f2ef21b3fe96ba455a029ab129447894b 100644 (file)
@@ -55,6 +55,7 @@ class Request {
         if ($daoName && !$daoName::isComponentEnabled()) {
           throw new \Civi\API\Exception\NotImplementedException("$entity API is not available because " . $daoName::COMPONENT . " component is disabled");
         }
+        // Extra arguments used e.g. by dynamic entities like Multi-Record custom groups & the ECK extension
         $args = (array) CoreUtil::getInfoItem($entity, 'class_args');
         $apiRequest = call_user_func_array($callable, $args);
         foreach ($params as $name => $param) {
index c40f3ec251b6712d88c34a8c86fecca0e0f352de..f6711dd72452bd6ad738bbd7ff8de1215f002647 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace Civi\Api4\Event\Subscriber;
 
+use Civi\API\Request;
 use Civi\Api4\Utils\CoreUtil;
 use Civi\Core\Event\GenericHookEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -66,7 +67,8 @@ class DefaultDisplaySubscriber extends \Civi\Core\Service\AutoService implements
     // Default sort order
     $e->display['settings']['sort'] = self::getDefaultSort($entityName);
 
-    $fields = CoreUtil::getApiClass($entityName)::get()->entityFields();
+    $apiGet = Request::create($entityName, 'get', ['version' => 4]);
+    $fields = $apiGet->entityFields();
     $columns = [$labelField];
     // Add grouping fields like "event_type_id" in the description
     $grouping = (array) (CoreUtil::getCustomGroupExtends($entityName)['grouping'] ?? []);