From 573fc5ae732c1cce442ac2fa73b650c715c34814 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 2 Nov 2022 10:39:45 -0400 Subject: [PATCH] Fix missing links in SearchKit results Regression: Go to SearchKit and click "New Search" (for contacts). The display name column is no longer a clickable link. --- .../Civi/Api4/Action/SearchDisplay/GetDefault.php | 2 +- .../api/v4/SearchDisplay/SearchDisplayTest.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php index 937041bd19..e340898b6d 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php @@ -199,7 +199,7 @@ class GetDefault extends \Civi\Api4\Generic\AbstractAction { */ private function getColumnLink(&$col, $clause) { if ($clause['expr'] instanceof SqlField || $clause['expr'] instanceof SqlFunctionGROUP_CONCAT) { - $field = $clause['fields'][0] ?? NULL; + $field = \CRM_Utils_Array::first($clause['fields'] ?? []); if ($field && CoreUtil::getInfoItem($field['entity'], 'label_field') === $field['name'] && !empty(CoreUtil::getInfoItem($field['entity'], 'paths')['view']) diff --git a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchDisplayTest.php b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchDisplayTest.php index d56366c6ad..a6033fc823 100644 --- a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchDisplayTest.php +++ b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchDisplayTest.php @@ -22,7 +22,7 @@ class SearchDisplayTest extends \PHPUnit\Framework\TestCase implements HeadlessI 'api_entity' => 'Contact', 'api_params' => [ 'version' => 4, - 'select' => ['first_name', 'last_name', 'contact_sub_type:label', 'gender_id'], + 'select' => ['first_name', 'display_name', 'contact_sub_type:label', 'gender_id'], 'where' => [], ], ]; @@ -37,6 +37,17 @@ class SearchDisplayTest extends \PHPUnit\Framework\TestCase implements HeadlessI $this->assertEquals('fa-table', $display['type:icon']); $this->assertEquals('Contact', $display['saved_search_id.api_entity']); $this->assertEquals('Contacts', $display['saved_search_id.api_entity:label']); + + // Default sort order should have been added + $this->assertEquals([['sort_name', 'ASC']], $display['settings']['sort']); + + // `display_name` column should have a link + $this->assertEquals('Contact', $display['settings']['columns'][1]['link']['entity']); + $this->assertEquals('view', $display['settings']['columns'][1]['link']['action']); + $this->assertEmpty($display['settings']['columns'][1]['link']['join']); + + // `first_name` column should not have a link + $this->assertArrayNotHasKey('link', $display['settings']['columns'][0]); } public function testGetDefaultNoEntity() { -- 2.25.1