Merge pull request #24109 from yashodha/reports_improvements
[civicrm-core.git] / Civi / API / Request.php
index 3a8d2da50b6b0b57dd291b594d9fdaa662391a76..55765a9bcb36401feb7715854a2334d62fea482f 100644 (file)
@@ -10,7 +10,7 @@
  */
 namespace Civi\API;
 
-use Civi\Api4\Event\CreateApi4RequestEvent;
+use Civi\Api4\Utils\CoreUtil;
 
 /**
  * Class Request
@@ -45,14 +45,9 @@ class Request {
         ];
 
       case 4:
-        // Load the API kernel service for registering API providers, as
-        // otherwise subscribers to the civi.api4.createRequest event registered
-        // through the EventSubscriberInterface will not be registered.
-        \Civi::service('civi_api_kernel');
-        $e = new CreateApi4RequestEvent($entity);
-        \Civi::dispatcher()->dispatch('civi.api4.createRequest', $e);
-        $callable = [$e->className, $action];
-        if (!$e->className || !is_callable($callable)) {
+        $className = CoreUtil::getApiClass($entity);
+        $callable = [$className, $action];
+        if (!$className || !is_callable($callable)) {
           throw new \Civi\API\Exception\NotImplementedException("API ($entity, $action) does not exist (join the API team and implement it!)");
         }
         // Check enabled components
@@ -60,7 +55,8 @@ class Request {
         if ($daoName && defined("{$daoName}::COMPONENT") && !\CRM_Core_Component::isEnabled($daoName::COMPONENT)) {
           throw new \Civi\API\Exception\NotImplementedException("$entity API is not available because " . $daoName::COMPONENT . " component is disabled");
         }
-        $apiRequest = call_user_func_array($callable, $e->args);
+        $args = (array) CoreUtil::getInfoItem($entity, 'class_args');
+        $apiRequest = call_user_func_array($callable, $args);
         foreach ($params as $name => $param) {
           $setter = 'set' . ucfirst($name);
           $apiRequest->$setter($param);