From ba149e212b56b56da04dc336375d8c6199773d10 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 16 Sep 2021 00:37:13 -0400 Subject: [PATCH] SearchKit - Exclude custom fields from ON clause selector 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 | 2 ++ .../ang/crmSearchAdmin/crmSearchAdmin.component.js | 3 ++- tests/phpunit/api/v4/Action/CustomValueTest.php | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Civi/Api4/Service/Spec/SpecFormatter.php b/Civi/Api4/Service/Spec/SpecFormatter.php index 413c1f3670..f570542309 100644 --- a/Civi/Api4/Service/Spec/SpecFormatter.php +++ b/Civi/Api4/Service/Spec/SpecFormatter.php @@ -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']); diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index f06792b4dd..0e7630d8bd 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -423,9 +423,10 @@ }; 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); diff --git a/tests/phpunit/api/v4/Action/CustomValueTest.php b/tests/phpunit/api/v4/Action/CustomValueTest.php index d2a0298720..de6df7c9bc 100644 --- a/tests/phpunit/api/v4/Action/CustomValueTest.php +++ b/tests/phpunit/api/v4/Action/CustomValueTest.php @@ -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", -- 2.25.1