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];
+ }
}
}
}
'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' => [
[
$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'];