SearchKit - Exclude custom fields from ON clause selector
authorColeman Watts <coleman@civicrm.org>
Thu, 16 Sep 2021 04:37:13 +0000 (00:37 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 16 Sep 2021 04:37:13 +0000 (00:37 -0400)
Custom fields cannot as-yet be added to an ON clause in APIv4
because they do not belong to the tables being joined.

This removes the tripping hazard from the UI, by making custom fields
unavailable to select in an ON clause.

Civi/Api4/Service/Spec/SpecFormatter.php
ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js
tests/phpunit/api/v4/Action/CustomValueTest.php

index 413c1f3670b8f85b323432a9517f82db1739fee9..f57054230906afc718963054284ee69eeaf273bd 100644 (file)
@@ -32,6 +32,8 @@ class SpecFormatter {
         $field->setName($data['custom_group_id.name'] . '.' . $data['name']);
       }
       else {
+        // Fields belonging to custom entities are treated as normal; type = Field instead of Custom
+        $field->setType('Field');
         $field->setTableName($data['custom_group_id.table_name']);
       }
       $field->setColumnName($data['column_name']);
index f06792b4dd88098c96470f4ebf7d70001ef09d50..0e7630d8bd5ee7c459942a852ff50449253e7b19 100644 (file)
       };
 
       function getFieldsForJoin(joinEntity) {
-        return {results: ctrl.getAllFields(':name', ['Field', 'Custom'], null, joinEntity)};
+        return {results: ctrl.getAllFields(':name', ['Field'], null, joinEntity)};
       }
 
+      // @return {function}
       $scope.fieldsForJoin = function(joinEntity) {
         if (!fieldsForJoinGetters[joinEntity]) {
           fieldsForJoinGetters[joinEntity] = _.wrap(joinEntity, getFieldsForJoin);
index d2a029872045a79ad332344fd999156f24b0c840..de6df7c9bcf049c71f8796a10306ffa0cfbb4d6e 100644 (file)
@@ -84,7 +84,7 @@ class CustomValueTest extends BaseCustomValueTest {
     $expectedResult = [
       [
         'custom_group' => $group,
-        'type' => 'Custom',
+        'type' => 'Field',
         'name' => $colorFieldName,
         'title' => $colorFieldName,
         'entity' => "Custom_$group",
@@ -97,7 +97,7 @@ class CustomValueTest extends BaseCustomValueTest {
       ],
       [
         'custom_group' => $group,
-        'type' => 'Custom',
+        'type' => 'Field',
         'name' => $multiFieldName,
         'title' => $multiFieldName,
         'entity' => "Custom_$group",
@@ -110,7 +110,7 @@ class CustomValueTest extends BaseCustomValueTest {
       ],
       [
         'custom_group' => $group,
-        'type' => 'Custom',
+        'type' => 'Field',
         'name' => $textFieldName,
         'title' => $textFieldName,
         'entity' => "Custom_$group",