diff --git a/ext/afform/mock/ang/testContactEmailSearchForm.aff.html b/ext/afform/mock/ang/testContactEmailSearchForm.aff.html index 2f3b1f8814de..390be362f67d 100644 --- a/ext/afform/mock/ang/testContactEmailSearchForm.aff.html +++ b/ext/afform/mock/ang/testContactEmailSearchForm.aff.html @@ -1,5 +1,6 @@
+
diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 4d95db8520d3..8a24c6b72f61 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -1014,22 +1014,28 @@ private function addFilterLabel($fieldName, $value) { if (!empty($field['options'])) { $options = civicrm_api4($field['entity'], 'getFields', [ 'loadOptions' => TRUE, + 'checkPermissions' => FALSE, 'where' => [['name', '=', $field['name']]], ])->first()['options'] ?? []; - if (!empty($options[$value])) { - $this->filterLabels[] = $options[$value]; + foreach ((array) $value as $val) { + if (!empty($options[$val])) { + $this->filterLabels[] = $options[$val]; + } } } elseif (!empty($field['fk_entity'])) { $idField = CoreUtil::getIdFieldName($field['fk_entity']); $labelField = CoreUtil::getInfoItem($field['fk_entity'], 'label_field'); if ($labelField) { - $record = civicrm_api4($field['fk_entity'], 'get', [ - 'where' => [[$idField, '=', $value]], + $records = civicrm_api4($field['fk_entity'], 'get', [ + 'checkPermissions' => $this->checkPermissions, + 'where' => [[$idField, 'IN', (array) $value]], 'select' => [$labelField], - ])->first() ?? NULL; - if (isset($record[$labelField])) { - $this->filterLabels[] = $record[$labelField]; + ]); + foreach ($records as $record) { + if (isset($record[$labelField])) { + $this->filterLabels[] = $record[$labelField]; + } } } } diff --git a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchAfformTest.php b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchAfformTest.php index 62ced4717894..577589455467 100644 --- a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchAfformTest.php +++ b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchAfformTest.php @@ -46,9 +46,7 @@ public function testRunWithAfform() { 'GROUP_CONCAT(DISTINCT Contact_Email_contact_id_01.email) AS GROUP_CONCAT_Contact_Email_contact_id_01_email', ], 'orderBy' => [], - 'where' => [ - ['contact_type:name', '=', 'Individual'], - ], + 'where' => [], 'groupBy' => ['id'], 'join' => [ [ @@ -147,6 +145,12 @@ public function testRunWithAfform() { $result = civicrm_api4('SearchDisplay', 'run', $params); $this->assertGreaterThan(1, $result->count()); + // For a filter with options, ensure labels are set + $params['filters'] = ['contact_type' => ['Individual']]; + $result = civicrm_api4('SearchDisplay', 'run', $params); + $this->assertGreaterThan(1, $result->count()); + $this->assertEquals(['Individual'], $result->labels); + // Note that filters add a wildcard so the value `afform_test` matches all 3 sample contacts; // But the Afform markup contains `filters="{last_name: 'AfformTest'}"` which only matches 2. $params['filters'] = ['source' => 'afform_test'];