SearchKit - Fix editable when displaying an icon
authorColeman Watts <coleman@civicrm.org>
Sun, 14 Aug 2022 20:47:31 +0000 (16:47 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 14 Aug 2022 20:50:56 +0000 (16:50 -0400)
Fixes a regression caused by #23404

Civi/Api4/Generic/DAOGetFieldsAction.php
ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php

index 77a97e82ec066288d48e2e1b219993cea3530f3d..7b8e848b1be3156ceea0f4a81d909d1f40b470a2 100644 (file)
@@ -105,14 +105,16 @@ class DAOGetFieldsAction extends BasicGetFieldsAction {
   private function formatValues() {
     foreach (array_keys($this->values) as $key) {
       if (strpos($key, ':')) {
-        [$fieldName, $suffix] = explode(':', $key);
-        $context = FormattingUtil::$pseudoConstantContexts[$suffix] ?? NULL;
-        if (!$context) {
-          throw new \API_Exception('Illegal expression');
+        if (isset($this->values[$key]) && $this->values[$key] !== '') {
+          [$fieldName, $suffix] = explode(':', $key);
+          $context = FormattingUtil::$pseudoConstantContexts[$suffix] ?? NULL;
+          // This only works for basic pseudoconstants like :name :label and :abbr. Skip others.
+          if ($context) {
+            $baoName = CoreUtil::getBAOFromApiName($this->getEntityName());
+            $options = $baoName::buildOptions($fieldName, $context) ?: [];
+            $this->values[$fieldName] = FormattingUtil::replacePseudoconstant($options, $this->values[$key], TRUE);
+          }
         }
-        $baoName = CoreUtil::getBAOFromApiName($this->getEntityName());
-        $options = $baoName::buildOptions($fieldName, $context) ?: [];
-        $this->values[$fieldName] = FormattingUtil::replacePseudoconstant($options, $this->values[$key], TRUE);
         unset($this->values[$key]);
       }
     }
index e0ce60a62e4192dd46d3ba5ab10d8b7f05f54c68..36fe1d73f19d96465d6c91469462854763b638f0 100644 (file)
@@ -365,6 +365,7 @@ class SearchRunTest extends \PHPUnit\Framework\TestCase implements HeadlessInter
               'label' => 'Name',
               'type' => 'field',
               'editable' => TRUE,
+              'icons' => [['field' => 'activity_type_id:icon', 'side' => 'left']],
             ],
             [
               'key' => 'Contact_Email_contact_id_01.email',