From: Eileen McNaughton Date: Thu, 23 Sep 2021 00:45:15 +0000 (+1200) Subject: Merge pull request #21574 from colemanw/searchPrimary X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=98c094e8696403fcb5e5825f9f43e70ae2d953bc;hp=29d047d701c7223e7999fc1f66381022c3dee0e7;p=civicrm-core.git Merge pull request #21574 from colemanw/searchPrimary Fixes dev/core#2852 - Add is_primary as a default SearchKit filter --- diff --git a/Civi/Api4/Address.php b/Civi/Api4/Address.php index a0e40683d4..a4ec60aeb3 100644 --- a/Civi/Api4/Address.php +++ b/Civi/Api4/Address.php @@ -19,6 +19,8 @@ namespace Civi\Api4; * Creating a new address requires at minimum a contact's ID and location type ID * and other attributes (although optional) like street address, city, country etc. * + * @ui_join_filters is_primary + * * @searchable secondary * @since 5.19 * @package Civi\Api4 diff --git a/Civi/Api4/Email.php b/Civi/Api4/Email.php index e9d02cbdee..16566d8c1e 100644 --- a/Civi/Api4/Email.php +++ b/Civi/Api4/Email.php @@ -17,6 +17,8 @@ namespace Civi\Api4; * * Creating a new email address requires at minimum a contact's ID and email * + * @ui_join_filters is_primary + * * @searchable secondary * @since 5.19 * @package Civi\Api4 diff --git a/Civi/Api4/IM.php b/Civi/Api4/IM.php index f6d8045f4d..75977dba3d 100644 --- a/Civi/Api4/IM.php +++ b/Civi/Api4/IM.php @@ -13,6 +13,8 @@ namespace Civi\Api4; /** * IM entity. * + * @ui_join_filters is_primary + * * @searchable secondary * @since 5.19 * @package Civi\Api4 diff --git a/Civi/Api4/Phone.php b/Civi/Api4/Phone.php index 8eeedf8de5..067864eeb1 100644 --- a/Civi/Api4/Phone.php +++ b/Civi/Api4/Phone.php @@ -17,6 +17,8 @@ namespace Civi\Api4; * * Creating a new phone of a contact, requires at minimum a contact's ID and phone number * + * @ui_join_filters is_primary + * * @searchable secondary * @since 5.19 * @package Civi\Api4 diff --git a/ext/search_kit/Civi/Search/Admin.php b/ext/search_kit/Civi/Search/Admin.php index bec6337299..ab7104d79a 100644 --- a/ext/search_kit/Civi/Search/Admin.php +++ b/ext/search_kit/Civi/Search/Admin.php @@ -355,13 +355,20 @@ class Admin { foreach ($entities as $entity) { foreach ($entity['ui_join_filters'] ?? [] as $fieldName) { $field = civicrm_api4($entity['name'], 'getFields', [ - 'select' => ['options'], + 'select' => ['options', 'data_type'], 'where' => [['name', '=', $fieldName]], 'loadOptions' => ['name'], ])->first(); - $value = isset($field['options'][0]) ? json_encode($field['options'][0]['name']) : ''; + $value = ''; + if ($field['data_type'] === 'Boolean') { + $value = TRUE; + } + elseif (isset($field['options'][0])) { + $fieldName .= ':name'; + $value = json_encode($field['options'][0]['name']); + } $conditions[] = [ - $alias . '.' . $fieldName . ($value ? ':name' : ''), + $alias . '.' . $fieldName, '=', $value, ];