From 2067db51aa356e67ef21566c824b3cfc28922ef0 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Fri, 8 May 2020 23:37:50 -0400 Subject: [PATCH] Admin console: remove superfluous code and don't hard-code sections --- CRM/Admin/Page/Admin.php | 54 ++++++++-------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/CRM/Admin/Page/Admin.php b/CRM/Admin/Page/Admin.php index fc4d291c32..8fb257635c 100644 --- a/CRM/Admin/Page/Admin.php +++ b/CRM/Admin/Page/Admin.php @@ -39,60 +39,28 @@ class CRM_Admin_Page_Admin extends CRM_Core_Page { ]; $config = CRM_Core_Config::singleton(); - if (in_array('CiviContribute', $config->enableComponents)) { - $groups['CiviContribute'] = ts('CiviContribute'); - } - - if (in_array('CiviMember', $config->enableComponents)) { - $groups['CiviMember'] = ts('CiviMember'); - } - - if (in_array('CiviEvent', $config->enableComponents)) { - $groups['CiviEvent'] = ts('CiviEvent'); - } - - if (in_array('CiviMail', $config->enableComponents)) { - $groups['CiviMail'] = ts('CiviMail'); - } - - if (in_array('CiviCase', $config->enableComponents)) { - $groups['CiviCase'] = ts('CiviCase'); - } - - if (in_array('CiviReport', $config->enableComponents)) { - $groups['CiviReport'] = ts('CiviReport'); - } - if (in_array('CiviCampaign', $config->enableComponents)) { - $groups['CiviCampaign'] = ts('CiviCampaign'); + foreach ($config->enableComponents as $component) { + $comp = CRM_Core_Component::get($component); + $groups[$comp->info['name']] = $comp->info['translatedName']; } $values = CRM_Core_Menu::getAdminLinks(); - $this->_showHide = new CRM_Core_ShowHideBlocks(); foreach ($groups as $group => $title) { $groupId = str_replace(' ', '_', $group); - - $this->_showHide->addShow("id_{$groupId}_show"); - $this->_showHide->addHide("id_{$groupId}"); - $v = CRM_Core_ShowHideBlocks::links($this, $groupId, '', '', FALSE); - if (isset($values[$group])) { - $adminPanel[$groupId] = $values[$group]; - $adminPanel[$groupId]['show'] = $v['show']; - $adminPanel[$groupId]['hide'] = $v['hide']; - $adminPanel[$groupId]['title'] = $title; - } - else { - $adminPanel[$groupId] = []; - $adminPanel[$groupId]['show'] = ''; - $adminPanel[$groupId]['hide'] = ''; - $adminPanel[$groupId]['title'] = $title; - } + $adminPanel[$groupId] = array_merge($values[$group] ?? [], ['title' => $title]); } CRM_Utils_Hook::alterAdminPanel($adminPanel); + foreach ($adminPanel as $groupId => $group) { + if (count($group) == 1) { + // Presumably the only thing is the title; remove the section. + // This is done here to give the hook a chance to edit the section. + unset($adminPanel[$groupId]); + } + } $this->assign('adminPanel', $adminPanel); - $this->_showHide->addToTemplate(); return parent::run(); } -- 2.25.1