Merge pull request #16877 from agileware/CIVICRM-1457
[civicrm-core.git] / CRM / Api4 / Page / Api4Explorer.php
index 73545ea22d11eb6904601f4e6e73f2a2f462be35..3daba0733836d8b0966bde5fbf613d298bfc36f6 100644 (file)
@@ -10,6 +10,8 @@
  +--------------------------------------------------------------------+
  */
 
+use Civi\Api4\Service\Schema\Joinable\Joinable;
+
 /**
  *
  * @package CRM
@@ -20,11 +22,18 @@ class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page {
   public function run() {
     $apiDoc = new ReflectionFunction('civicrm_api4');
     $groupOptions = civicrm_api4('Group', 'getFields', ['loadOptions' => TRUE, 'select' => ['options', 'name'], 'where' => [['name', 'IN', ['visibility', 'group_type']]]]);
+    // Don't show n-to-many joins in Explorer
+    $entityLinks = (array) civicrm_api4('Entity', 'getLinks', [], ['entity' => 'links']);
+    foreach ($entityLinks as $entity => $links) {
+      $entityLinks[$entity] = array_filter($links, function($link) {
+        return $link['joinType'] != Joinable::JOIN_TYPE_ONE_TO_MANY;
+      });
+    }
     $vars = [
       'operators' => \CRM_Core_DAO::acceptedSQLOperators(),
       'basePath' => Civi::resources()->getUrl('civicrm'),
       'schema' => (array) \Civi\Api4\Entity::get()->setChain(['fields' => ['$name', 'getFields']])->execute(),
-      'links' => (array) \Civi\Api4\Entity::getLinks()->execute(),
+      'links' => $entityLinks,
       'docs' => \Civi\Api4\Utils\ReflectionUtils::parseDocBlock($apiDoc->getDocComment()),
       'functions' => self::getSqlFunctions(),
       'groupOptions' => array_column((array) $groupOptions, 'options', 'name'),
@@ -61,7 +70,9 @@ class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page {
         if (is_subclass_of($className, '\Civi\Api4\Query\SqlFunction')) {
           $fns[] = [
             'name' => $className::getName(),
+            'title' => $className::getTitle(),
             'params' => $className::getParams(),
+            'category' => $className::getCategory(),
           ];
         }
       }