From ecc0b99423530890bc1a276e20548c3e71ad7e40 Mon Sep 17 00:00:00 2001 From: benjamin Date: Thu, 2 Jan 2025 18:19:39 +0000 Subject: [PATCH 1/2] refactor contact summary tabs to use TabHeader.tpl --- CRM/Contact/Page/View/Summary.php | 13 ++++++-- CRM/Core/Smarty.php | 5 +++ templates/CRM/Contact/Page/View/Summary.tpl | 29 +---------------- templates/CRM/common/TabHeader.tpl | 35 +++++++++++---------- 4 files changed, 35 insertions(+), 47 deletions(-) diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index 732bd34b848..c71b08e394e 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -469,9 +469,18 @@ public function getTabs(array $contact) { // ensure all keys used in the template are set, to avoid notices $allTabs = \CRM_Core_Smarty::setRequiredTabTemplateKeys($allTabs); + // ensure the array keys match the value in the "id" of each item + $tabs = []; + + foreach ($allTabs as $key => $tab) { + $finalKey = $tab['id'] ?? $key; + $tabs[$finalKey] = $tab; + } + // now sort the tabs based on weight - usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']); - return $allTabs; + usort($tabs, ['CRM_Utils_Sort', 'cmpFunc']); + + return $tabs; } /** diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index a0cc739ae9f..61245fedc0a 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -299,12 +299,17 @@ public static function setRequiredTabTemplateKeys(array $tabs): array { 'count' => NULL, 'hideCount' => FALSE, 'template' => NULL, + 'active' => TRUE, + 'valid' => TRUE, // Afform tabs set the afform module and directive - NULL for non-afform tabs 'module' => NULL, 'directive' => NULL, ]; foreach ($tabs as $i => $tab) { + if (empty($tab['url'])) { + $tab['url'] = $tab['link'] ?? ''; + } $tabs[$i] = array_merge($defaults, (array) $tab); } return $tabs; diff --git a/templates/CRM/Contact/Page/View/Summary.tpl b/templates/CRM/Contact/Page/View/Summary.tpl index beb28d67fce..63a6a7733d3 100644 --- a/templates/CRM/Contact/Page/View/Summary.tpl +++ b/templates/CRM/Contact/Page/View/Summary.tpl @@ -101,35 +101,8 @@ {/if} -
-
- + {include file='CRM/common/TabHeader.tpl' tabHeader=$allTabs containerClasses="crm-contact-page crm-inline-edit-container" listClasses="crm-contact-tabs-list" tabIdPrefix="contact-"} - {foreach from=$allTabs item=tabValue} - {if $tabValue.template} -
- {if $tabValue.module} - - {include file=$tabValue.template afform=$tabValue} - {else} - {include file=$tabValue.template} - {/if} -
- {/if} - {/foreach} -
-
-
{/if} {* CRM-10560 *} diff --git a/templates/CRM/common/TabHeader.tpl b/templates/CRM/common/TabHeader.tpl index 9689ebcf3c1..8d7fc50d5e3 100644 --- a/templates/CRM/common/TabHeader.tpl +++ b/templates/CRM/common/TabHeader.tpl @@ -8,27 +8,28 @@ +--------------------------------------------------------------------+ *} {* enclose all tabs and its content in a block *} -
+
{if $tabHeader}
- + {foreach from=$tabHeader key=tabName item=tabValue} {if $tabValue.template} -
+
{if $tabValue.module} {include file=$tabValue.template afform=$tabValue} @@ -41,4 +42,4 @@
{/if}
-
{* crm-content-block ends here *} +
From de309b02d7a535d68dd8f93b5ae9c83d435904d2 Mon Sep 17 00:00:00 2001 From: benjamin Date: Thu, 2 Jan 2025 18:35:23 +0000 Subject: [PATCH 2/2] add icons to Manage Event tabs --- CRM/Event/Form/ManageEvent.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index 69297b8c492..bee5082d7a1 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -430,21 +430,21 @@ private function processTab() { ]; $tabs = []; - $tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage'] + $default; - $tabs['location'] = ['title' => ts('Event Location')] + $default; + $tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage', 'icon' => 'crm-i fa-circle-info'] + $default; + $tabs['location'] = ['title' => ts('Event Location'), 'icon' => 'crm-i fa-map-marker'] + $default; // If CiviContribute is active, create the Fees tab. if (CRM_Core_Component::isEnabled('CiviContribute')) { - $tabs['fee'] = ['title' => ts('Fees')] + $default; + $tabs['fee'] = ['title' => ts('Fees'), 'icon' => 'crm-i fa-money'] + $default; } - $tabs['registration'] = ['title' => ts('Online Registration')] + $default; + $tabs['registration'] = ['title' => ts('Online Registration'), 'icon' => 'crm-i fa-check'] + $default; // @fixme I don't understand the event permissions check here - can we just get rid of it? $permissions = CRM_Event_BAO_Event::getAllPermissions(); if (CRM_Core_Permission::check('administer CiviCRM data') || !empty($permissions[CRM_Core_Permission::EDIT])) { - $tabs['reminder'] = ['title' => ts('Schedule Reminders'), 'class' => 'livePage'] + $default; + $tabs['reminder'] = ['title' => ts('Schedule Reminders'), 'class' => 'livePage', 'icon' => 'crm-i fa-envelope'] + $default; } - $tabs['pcp'] = ['title' => ts('Personal Campaigns')] + $default; - $tabs['repeat'] = ['title' => ts('Repeat')] + $default; + $tabs['pcp'] = ['title' => ts('Personal Campaigns'), 'icon' => 'crm-i fa-user'] + $default; + $tabs['repeat'] = ['title' => ts('Repeat'), 'icon' => 'crm-i fa-repeat'] + $default; // Repeat tab must refresh page when switching repeat mode so js & vars will get set-up if (!$this->_isRepeatingEvent) {