Skip to content

Commit

Permalink
Merge pull request #27123 from colemanw/searchKitKey
Browse files Browse the repository at this point in the history
dev/core#4519 SearchKit - Fix tasks when ID column is not present
  • Loading branch information
eileenmcnaughton authored Aug 24, 2023
2 parents 45c83bd + 5e66fa9 commit b16f16e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ protected function formatResult(iterable $result): array {
'columns' => $columns,
'cssClass' => implode(' ', $style),
];
if (isset($data[$keyName])) {
$row['key'] = $data[$keyName];
if (isset($record[$keyName])) {
$row['key'] = $record[$keyName];
}
$rows[] = $row;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ public function testInPlaceEditAndCreate() {
];
$result = civicrm_api4('SearchDisplay', 'run', $params);

$this->assertEquals($contacts[0], $result[0]['key']);

// Contact 1 first name can be updated
$this->assertEquals('One', $result[0]['columns'][0]['val']);
$this->assertEquals($contacts[0], $result[0]['columns'][0]['edit']['record']['id']);
Expand Down Expand Up @@ -1507,6 +1509,7 @@ public function testEditableContactFields() {
// Second Individual
$expectedFirstNameEdit['record']['id'] = $contact[1]['id'];
$expectedFirstNameEdit['value'] = NULL;
$this->assertEquals($contact[1]['id'], $result[1]['key']);
$this->assertEquals($expectedFirstNameEdit, $result[1]['columns'][0]['edit']);
$this->assertTrue(!isset($result[1]['columns'][1]['edit']));
$this->assertTrue(!isset($result[1]['columns'][2]['edit']));
Expand Down Expand Up @@ -1743,6 +1746,49 @@ public function testContactTypeIcons(): void {
$this->assertEquals('fa-star', $result[2]['columns'][0]['icons'][0]['class']);
}

public function testKeyIsReturned(): void {
$id = $this->createTestRecord('Email')['id'];
$params = [
'checkPermissions' => FALSE,
'return' => 'page:1',
'savedSearch' => [
'api_entity' => 'Email',
'api_params' => [
'version' => 4,
'select' => ['email'],
'where' => [
['id', 'IN', [$id]],
],
],
],
'display' => [
'type' => 'table',
'label' => '',
'settings' => [
'limit' => 20,
'pager' => TRUE,
'actions' => TRUE,
'columns' => [
[
'key' => 'email',
'label' => 'Email',
'dataType' => 'String',
'type' => 'field',
],
],
'sort' => [
['id', 'ASC'],
],
],
],
'afform' => NULL,
];

$result = civicrm_api4('SearchDisplay', 'run', $params);
$this->assertCount(1, $result);
$this->assertEquals($id, $result[0]['key']);
}

/**
* Returns all contacts in VIEW mode but only specified contact for EDIT.
*
Expand Down

0 comments on commit b16f16e

Please sign in to comment.