From: Coleman Watts Date: Wed, 27 Apr 2022 16:55:47 +0000 (+0200) Subject: APIv4 - Move filtering of component entities higher up X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=35be577cf61367d9748d08cdbb705ceffc64a4db;p=civicrm-core.git APIv4 - Move filtering of component entities higher up Filtering out component entities at a low level was causing errors when trying to get basic info about an entity from a disabled component. It's better to do the filtering in the Entity.get action instead. --- diff --git a/Civi/Api4/Action/Entity/Get.php b/Civi/Api4/Action/Entity/Get.php index 9a8ccbb5f9..13b96573fe 100644 --- a/Civi/Api4/Action/Entity/Get.php +++ b/Civi/Api4/Action/Entity/Get.php @@ -28,11 +28,15 @@ class Get extends \Civi\Api4\Generic\BasicGetAction { protected $includeCustom; /** - * Returns all APIv4 entities + * Returns all APIv4 entities from core, enabled components and enabled extensions. */ protected function getRecords() { $provider = \Civi::service('action_object_provider'); - return $provider->getEntities(); + return array_filter($provider->getEntities(), function($entity) { + // Only include DAO entities from enabled components + $daoName = $entity['dao'] ?? NULL; + return (!$daoName || !defined("{$daoName}::COMPONENT") || \CRM_Core_Component::isEnabled($daoName::COMPONENT)); + }); } } diff --git a/Civi/Api4/Provider/ActionObjectProvider.php b/Civi/Api4/Provider/ActionObjectProvider.php index 2c284e3cc0..4d6dda02df 100644 --- a/Civi/Api4/Provider/ActionObjectProvider.php +++ b/Civi/Api4/Provider/ActionObjectProvider.php @@ -152,7 +152,8 @@ class ActionObjectProvider implements EventSubscriberInterface, ProviderInterfac if (!$entities) { // Load entities declared in API files foreach ($this->getAllApiClasses() as $className) { - $this->loadEntity($className, $entities); + $info = $className::getInfo(); + $entities[$info['name']] = $info; } // Allow extensions to modify the list of entities $event = GenericHookEvent::create(['entities' => &$entities]); @@ -164,19 +165,6 @@ class ActionObjectProvider implements EventSubscriberInterface, ProviderInterfac return $entities; } - /** - * @param \Civi\Api4\Generic\AbstractEntity $className - * @param array $entities - */ - private function loadEntity($className, array &$entities) { - $info = $className::getInfo(); - $daoName = $info['dao'] ?? NULL; - // Only include DAO entities from enabled components - if (!$daoName || !defined("{$daoName}::COMPONENT") || \CRM_Core_Component::isEnabled($daoName::COMPONENT)) { - $entities[$info['name']] = $info; - } - } - /** * Scan all api directories to discover entities * @return \Civi\Api4\Generic\AbstractEntity[]