From c00da2544278d5d46b02a684a12085298a01656e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 14 Aug 2022 16:47:31 -0400 Subject: [PATCH] SearchKit - Fix editable when displaying an icon Fixes a regression caused by #23404 --- Civi/Api4/Generic/DAOGetFieldsAction.php | 16 +++++++++------- .../api/v4/SearchDisplay/SearchRunTest.php | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Civi/Api4/Generic/DAOGetFieldsAction.php b/Civi/Api4/Generic/DAOGetFieldsAction.php index 77a97e82ec06..7b8e848b1be3 100644 --- a/Civi/Api4/Generic/DAOGetFieldsAction.php +++ b/Civi/Api4/Generic/DAOGetFieldsAction.php @@ -105,14 +105,16 @@ private function getFkFieldSpec($fieldName, $fields) { 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]); } } diff --git a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php index e0ce60a62e41..36fe1d73f19d 100644 --- a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php +++ b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php @@ -365,6 +365,7 @@ public function testInPlaceEditAndCreate() { 'label' => 'Name', 'type' => 'field', 'editable' => TRUE, + 'icons' => [['field' => 'activity_type_id:icon', 'side' => 'left']], ], [ 'key' => 'Contact_Email_contact_id_01.email',