Skip to content

Commit

Permalink
APIv4 - Use new class_args metadata to remove special handing for Cus…
Browse files Browse the repository at this point in the history
…tomValue and CiviCase entities.

Before: When creating an API request, special logic was needed for CustomValue and CiviCase apis.
After: Metadata used.
  • Loading branch information
colemanw committed Feb 28, 2022
1 parent 7abc056 commit 0f55afc
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions Civi/Api4/Event/Subscriber/CreateApi4RequestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? [];
}
}

Expand Down

0 comments on commit 0f55afc

Please sign in to comment.