From 4c734e6494a7783a393f3b1bf6e0b045f02e02ad Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 31 Oct 2023 07:57:22 -0400 Subject: [PATCH] SearchKit - Use getLinks API action --- ext/search_kit/Civi/Search/Display.php | 42 ++++++-------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/ext/search_kit/Civi/Search/Display.php b/ext/search_kit/Civi/Search/Display.php index 413a3c5d9a..aeadde64dd 100644 --- a/ext/search_kit/Civi/Search/Display.php +++ b/ext/search_kit/Civi/Search/Display.php @@ -12,7 +12,6 @@ namespace Civi\Search; use CRM_Search_ExtensionUtil as E; -use Civi\Api4\Utils\CoreUtil; /** * Class Display @@ -58,42 +57,19 @@ class Display { * @return array[] */ public static function getEntityLinks(string $entity, $addLabel = FALSE): array { - $paths = CoreUtil::getInfoItem($entity, 'paths') ?? []; - $links = []; - // Hack to support links to relationships - if ($entity === 'RelationshipCache') { - $entity = 'Relationship'; - } - if ($addLabel === TRUE) { - $addLabel = CoreUtil::getInfoItem($entity, 'title'); - } - // If addLabel is false the placeholder needs to be passed through to javascript - $label = $addLabel ?: '%1'; + $links = (array) civicrm_api4($entity, 'getLinks', [ + 'checkPermissions' => FALSE, + 'entityTitle' => $addLabel, + 'select' => ['ui_action', 'entity', 'text', 'icon', 'target'], + ]); $styles = [ 'delete' => 'danger', 'add' => 'primary', ]; - foreach (array_keys($paths) as $actionName) { - $actionKey = \CRM_Core_Action::mapItem($actionName); - $link = [ - 'action' => $actionName, - 'entity' => $entity, - 'text' => \CRM_Core_Action::getTitle($actionKey, $label), - 'icon' => \CRM_Core_Action::getIcon($actionKey), - 'weight' => \CRM_Core_Action::getWeight($actionKey), - 'style' => $styles[$actionName] ?? 'default', - 'target' => 'crm-popup', - ]; - // Contacts and cases are too cumbersome to view in a popup - if (in_array($entity, ['Contact', 'Case']) && in_array($actionName, ['view', 'update'])) { - $link['target'] = '_blank'; - } - $links[$actionName] = $link; - } - // Sort by weight, then discard it - uasort($links, ['CRM_Utils_Sort', 'cmpFunc']); - foreach ($links as $index => $link) { - unset($links[$index]['weight']); + foreach ($links as &$link) { + $link['action'] = $link['ui_action']; + $link['style'] = $styles[$link['ui_action']] ?? 'default'; + unset($link['ui_action']); } return $links; } -- 2.25.1