Admin console: remove superfluous code and don't hard-code sections
authorAndrew Hunt <andrew@aghstrategies.com>
Sat, 9 May 2020 03:37:50 +0000 (23:37 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Sun, 10 May 2020 19:30:39 +0000 (15:30 -0400)
CRM/Admin/Page/Admin.php

index fc4d291c320f61d4d4870b4bd2d4be30af3c2fff..8fb257635cabff3f79bd8bc21fa9591a589e92cf 100644 (file)
@@ -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();
   }