From 350c6a5c58b3379c3f007fa57cf1ab8724583d56 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sat, 23 Dec 2023 14:38:05 -0500 Subject: [PATCH] SearchKit - When replacing a contact summary tab with an afform, hide the core tab --- ext/afform/core/afform.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 88bdbf6984..1c4d2120de 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -167,6 +167,7 @@ function afform_civicrm_tabset($tabsetName, &$tabs, $context) { if ($tabsetName !== 'civicrm/contact/view') { return; } + $existingTabs = array_combine(array_keys($tabs), array_column($tabs, 'id')); $contactTypes = array_merge((array) ($context['contact_type'] ?? []), $context['contact_sub_type'] ?? []); $afforms = Civi\Api4\Afform::get(FALSE) ->addSelect('name', 'title', 'icon', 'module_name', 'directive_name', 'summary_contact_type', 'summary_weight') @@ -179,6 +180,11 @@ function afform_civicrm_tabset($tabsetName, &$tabs, $context) { if (!$summaryContactType || !$contactTypes || array_intersect($summaryContactType, $contactTypes)) { // Convention is to name the afform like "afformTabMyInfo" which gets the tab name "my_info" $tabId = CRM_Utils_String::convertStringToSnakeCase(preg_replace('#^(afformtab|afsearchtab|afform|afsearch)#i', '', $afform['name'])); + // If a tab with that id already exists, allow the afform to replace it. + $existingTab = array_search($tabId, $existingTabs); + if ($existingTab !== FALSE) { + unset($tabs[$existingTab]); + } $tabs[] = [ 'id' => $tabId, 'title' => $afform['title'], -- 2.25.1