Merge pull request #21574 from colemanw/searchPrimary
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 23 Sep 2021 00:45:15 +0000 (12:45 +1200)
committerGitHub <noreply@github.com>
Thu, 23 Sep 2021 00:45:15 +0000 (12:45 +1200)
Fixes dev/core#2852 - Add is_primary as a default SearchKit filter

Civi/Api4/Address.php
Civi/Api4/Email.php
Civi/Api4/IM.php
Civi/Api4/Phone.php
ext/search_kit/Civi/Search/Admin.php

index a0e40683d44fc01cb5ae874be24caabc25befd7a..a4ec60aeb31eefeeac3fa2cd34681d97bd8f3877 100644 (file)
@@ -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
index e9d02cbdee9a90fc2a2c3c85a7ed1727a95bc044..16566d8c1e1b5cb80d34efcd7a49f7791039a2aa 100644 (file)
@@ -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
index f6d8045f4de86070a197fab017767687a898c42b..75977dba3d16295ef2ccc8f17ca0a9a4fd9a155f 100644 (file)
@@ -13,6 +13,8 @@ namespace Civi\Api4;
 /**
  * IM entity.
  *
+ * @ui_join_filters is_primary
+ *
  * @searchable secondary
  * @since 5.19
  * @package Civi\Api4
index 8eeedf8de5b0a17a5fcf9ecbe6e4f6c00a25bce1..067864eeb10baf5b6882f218887a9a80c92616ea 100644 (file)
@@ -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
index bec6337299d005a1d94f94991a3cdc1fcc861f39..ab7104d79a3b9ccedae1944bd84b307564fd931b 100644 (file)
@@ -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,
         ];