From 0f55afcbb264537ccfddbcbbd64097cf9a7a174d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 28 Feb 2022 13:19:47 -0500 Subject: [PATCH] APIv4 - Use new class_args metadata to remove special handing for CustomValue and CiviCase entities. Before: When creating an API request, special logic was needed for CustomValue and CiviCase apis. After: Metadata used. --- .../CreateApi4RequestSubscriber.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Civi/Api4/Event/Subscriber/CreateApi4RequestSubscriber.php b/Civi/Api4/Event/Subscriber/CreateApi4RequestSubscriber.php index 519498efd0f8..505fe4095fa1 100644 --- a/Civi/Api4/Event/Subscriber/CreateApi4RequestSubscriber.php +++ b/Civi/Api4/Event/Subscriber/CreateApi4RequestSubscriber.php @@ -37,20 +37,11 @@ public static function getSubscribedEvents() { * @param \Civi\Api4\Event\CreateApi4RequestEvent $event */ public function onApiRequestCreate(\Civi\Api4\Event\CreateApi4RequestEvent $event) { - // Multi-record custom data entities - if (strpos($event->entityName, 'Custom_') === 0) { - $groupName = substr($event->entityName, 7); - if (CoreUtil::isCustomEntity($groupName)) { - $event->className = 'Civi\Api4\CustomValue'; - $event->args = [$groupName]; - } - } - else { - // Because "Case" is a reserved php keyword - $className = 'Civi\Api4\\' . ($event->entityName === 'Case' ? 'CiviCase' : $event->entityName); - if (class_exists($className)) { - $event->className = $className; - } + $provider = \Civi::service('action_object_provider'); + $info = $provider->getEntities()[$event->entityName] ?? NULL; + if ($info) { + $event->className = $info['class']; + $event->args = $info['class_args'] ?? []; } }