From fcae142a3968aa726d91a53cdcb195884b5cff85 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 11 Nov 2021 10:19:34 -0500 Subject: [PATCH] Fix tabs getting overwritten by double foreach loop --- CRM/Contact/Page/View/Summary.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index d05569362e..b28cfcfa46 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -435,8 +435,12 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { $context = ['contact_id' => $this->_contactId]; CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); - // Get tab counts last to avoid wasting time; if a tab was removed by hook, the count isn't needed. + $expectedKeys = ['count', 'class', 'template', 'hideCount', 'icon']; + foreach ($allTabs as &$tab) { + // Ensure tab has all expected keys + $tab += array_fill_keys($expectedKeys, NULL); + // Get tab counts last to avoid wasting time; if a tab was removed by hook, the count isn't needed. if (!isset($tab['count']) && isset($getCountParams[$tab['id']])) { $tab['count'] = call_user_func_array(['CRM_Contact_BAO_Contact', 'getCountComponent'], $getCountParams[$tab['id']]); } @@ -444,14 +448,6 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { // now sort the tabs based on weight usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']); - $expectedKeys = ['count', 'class', 'template', 'hideCount', 'icon']; - foreach ($allTabs as $index => $tab) { - foreach ($expectedKeys as $key) { - if (!array_key_exists($key, $tab)) { - $allTabs[$index][$key] = NULL; - } - } - } return $allTabs; } -- 2.25.1