Skip to content

Commit

Permalink
Merge pull request #29208 from colemanw/fixIrrelevantLinks
Browse files Browse the repository at this point in the history
SearchKit - Remove irrelevant links from default display
  • Loading branch information
eileenmcnaughton authored Feb 3, 2024
2 parents 582ab8a + dc4e57b commit 12ba587
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ private function getColumnLink(&$col, $clause) {
*/
public function getLinksMenu() {
$menu = [];
$discard = array_flip(['add', 'browse']);
$exclude = ['add', 'browse'];
$mainEntity = $this->savedSearch['api_entity'] ?? NULL;
if ($mainEntity && !$this->canAggregate(CoreUtil::getIdFieldName($mainEntity))) {
foreach (array_diff_key(Display::getEntityLinks($mainEntity, TRUE), $discard) as $link) {
foreach (Display::getEntityLinks($mainEntity, TRUE, $exclude) as $link) {
$link['join'] = NULL;
$menu[] = $link;
}
Expand All @@ -159,7 +159,7 @@ public function getLinksMenu() {
if (!$this->canAggregate($join['alias'] . '.' . CoreUtil::getIdFieldName($join['entity']))) {
foreach (array_filter(array_intersect_key($join, $keys)) as $joinEntity) {
$joinLabel = $this->getJoinLabel($join['alias']);
foreach (array_diff_key(Display::getEntityLinks($joinEntity, $joinLabel), $discard) as $link) {
foreach (Display::getEntityLinks($joinEntity, $joinLabel, $exclude) as $link) {
$link['join'] = $join['alias'];
$menu[] = $link;
}
Expand Down
11 changes: 8 additions & 3 deletions ext/search_kit/Civi/Search/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ public static function getDisplayTypes(array $props):array {
* @param string|bool $addLabel
* Pass a string to supply a custom label, TRUE to use the default,
* or FALSE to keep the %1 placeholders in the text (used for the admin UI)
* @param array|null $excludeActions
* @return array[]
*/
public static function getEntityLinks(string $entity, $addLabel = FALSE): array {
$links = (array) civicrm_api4($entity, 'getLinks', [
public static function getEntityLinks(string $entity, $addLabel = FALSE, array $excludeActions = NULL): array {
$apiParams = [
'checkPermissions' => FALSE,
'entityTitle' => $addLabel,
'select' => ['ui_action', 'entity', 'text', 'icon', 'target'],
]);
];
if ($excludeActions) {
$apiParams['where'][] = ['ui_action', 'NOT IN', $excludeActions];
}
$links = (array) civicrm_api4($entity, 'getLinks', $apiParams);
$styles = [
'delete' => 'danger',
'add' => 'primary',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,22 @@ public function testDefaultDisplayLinks(): void {
$this->assertCount(1, $result[1]['columns'][1]['links']);
$this->assertCount(1, $result[2]['columns'][0]['links']);
$this->assertCount(1, $result[2]['columns'][1]['links']);
$this->assertContains('View Group', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertContains('Update Group', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertContains('Delete Group', array_column($result[0]['columns'][2]['links'], 'text'));
// Add and browse links should not be shown in rows
$this->assertNotContains('Add Group', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertNotContains('Browse Group', array_column($result[0]['columns'][2]['links'], 'text'));
// No contact links in 1st row since the group is empty
$this->assertNotContains('View Contact', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertNotContains('Delete Contact', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertContains('View Contact', array_column($result[1]['columns'][2]['links'], 'text'));
$this->assertContains('Delete Contact', array_column($result[1]['columns'][2]['links'], 'text'));
$this->assertContains('View Contact', array_column($result[2]['columns'][2]['links'], 'text'));
$this->assertContains('Delete Contact', array_column($result[2]['columns'][2]['links'], 'text'));
// Add and browse links should not be shown in rows
$this->assertNotContains('Add Contact', array_column($result[1]['columns'][2]['links'], 'text'));
$this->assertNotContains('Browse Contact', array_column($result[2]['columns'][2]['links'], 'text'));
}

/**
Expand Down

0 comments on commit 12ba587

Please sign in to comment.