Fix NavTabs to return agreed navbar contract

This commit is contained in:
Dillon-Brown 2020-02-17 09:49:27 +00:00
parent 18cf64c8ad
commit fdb97afcb3
2 changed files with 122 additions and 75 deletions

View file

@ -5,6 +5,7 @@ namespace SuiteCRM\Core\Legacy;
use RuntimeException;
use TabController;
use GroupedTabStructure;
use TabGroupHelper;
/**
* Class Navbar
@ -21,7 +22,9 @@ class Navbar extends LegacyHandler
require LEGACY_PATH . 'modules/MySettings/TabController.php';
$tabArray = (new TabController())->get_tabs($GLOBALS['current_user']);
return $tabArray[0];
$tabArray = array_keys(array_change_key_case($tabArray[0], CASE_LOWER));
sort($tabArray);
return $tabArray;
}
throw new RuntimeException('Running legacy entry point failed');
@ -33,10 +36,38 @@ class Navbar extends LegacyHandler
public function getGroupedNavTabs(): array
{
if ($this->runLegacyEntryPoint()) {
global $moduleList;
require LEGACY_PATH . 'include/GroupedTabs/GroupedTabStructure.php';
global $current_language;
return (new GroupedTabStructure())->get_tab_structure($moduleList);
require_once LEGACY_PATH . 'include/GroupedTabs/GroupedTabStructure.php';
require_once LEGACY_PATH . 'modules/Studio/TabGroups/TabGroupHelper.php';
$tg = new TabGroupHelper();
$selectedAppLanguages = return_application_language($current_language);
$availableModules = $tg->getAvailableModules($current_language);
$modList = array_keys($availableModules);
$modList = array_combine($modList, $modList);
$groupedTabStructure = (new GroupedTabStructure())->get_tab_structure($modList, '', true, true);
foreach ($groupedTabStructure as $mainTab => $subModules) {
$groupedTabStructure[$mainTab]['label'] = $mainTab;
$groupedTabStructure[$mainTab]['labelValue'] = strtolower($selectedAppLanguages[$mainTab]);
$submoduleArray = [];
foreach ($subModules['modules'] as $submodule) {
$submoduleArray[] = strtolower($submodule);
}
sort($submoduleArray);
$output[] = [
'name' => $groupedTabStructure[$mainTab]['labelValue'],
'labelKey' => $mainTab,
'modules' => array_values($submoduleArray)
];
}
return $output;
}
throw new RuntimeException('Running legacy entry point failed');

View file

@ -58,44 +58,45 @@ final class NavbarTest extends Unit
public function testGetNonGroupedNavTabs(): void
{
// Ordered array
$expected = [
'Home' => 'Home',
'Accounts' => 'Accounts',
'Contacts' => 'Contacts',
'Opportunities' => 'Opportunities',
'Leads' => 'Leads',
'AOS_Quotes' => 'AOS_Quotes',
'Calendar' => 'Calendar',
'Documents' => 'Documents',
'Emails' => 'Emails',
'Spots' => 'Spots',
'Campaigns' => 'Campaigns',
'Calls' => 'Calls',
'Meetings' => 'Meetings',
'Tasks' => 'Tasks',
'Notes' => 'Notes',
'AOS_Invoices' => 'AOS_Invoices',
'AOS_Contracts' => 'AOS_Contracts',
'Cases' => 'Cases',
'Prospects' => 'Prospects',
'ProspectLists' => 'ProspectLists',
'Project' => 'Project',
'AM_ProjectTemplates' => 'AM_ProjectTemplates',
'FP_events' => 'FP_events',
'FP_Event_Locations' => 'FP_Event_Locations',
'AOS_Products' => 'AOS_Products',
'AOS_Product_Categories' => 'AOS_Product_Categories',
'AOS_PDF_Templates' => 'AOS_PDF_Templates',
'jjwg_Maps' => 'jjwg_Maps',
'jjwg_Markers' => 'jjwg_Markers',
'jjwg_Areas' => 'jjwg_Areas',
'jjwg_Address_Cache' => 'jjwg_Address_Cache',
'AOR_Reports' => 'AOR_Reports',
'AOW_WorkFlow' => 'AOW_WorkFlow',
'AOK_KnowledgeBase' => 'AOK_KnowledgeBase',
'AOK_Knowledge_Base_Categories' => 'AOK_Knowledge_Base_Categories',
'EmailTemplates' => 'EmailTemplates',
'Surveys' => 'Surveys'
'accounts',
'am_projecttemplates',
'aok_knowledge_base_categories',
'aok_knowledgebase',
'aor_reports',
'aos_contracts',
'aos_invoices',
'aos_pdf_templates',
'aos_product_categories',
'aos_products',
'aos_quotes',
'aow_workflow',
'calendar',
'calls',
'campaigns',
'cases',
'contacts',
'documents',
'emails',
'emailtemplates',
'fp_event_locations',
'fp_events',
'home',
'jjwg_address_cache',
'jjwg_areas',
'jjwg_maps',
'jjwg_markers',
'leads',
'meetings',
'notes',
'opportunities',
'project',
'prospectlists',
'prospects',
'spots',
'surveys',
'tasks',
];
$this->assertSame(
@ -107,54 +108,69 @@ final class NavbarTest extends Unit
public function testGroupNavTabs(): void
{
$expected = [
'Sales' => [
0 => [
'name' => 'sales',
'labelKey' => 'LBL_TABGROUP_SALES',
// Ordered array
'modules' => [
'Home' => 'Home',
'Accounts' => 'Accounts',
'Contacts' => 'Contacts',
'Opportunities' => 'Opportunities',
'Leads' => 'Leads'
'accounts',
'contacts',
'home',
'leads',
'opportunities',
]
],
'Marketing' => [
1 => [
'name' => 'marketing',
'labelKey' => 'LBL_TABGROUP_MARKETING',
// Ordered array
'modules' => [
'Home' => 'Home',
'Accounts' => 'Accounts',
'Contacts' => 'Contacts',
'Leads' => 'Leads',
'Campaigns' => 'Campaigns',
'Prospects' => 'Targets',
'ProspectLists' => 'Targets - Lists'
'accounts',
'campaigns',
'contacts',
'home',
'leads',
'targets',
'targets - lists',
]
],
'Support' => [
2 => [
'name' => 'support',
'labelKey' => 'LBL_TABGROUP_SUPPORT',
// Ordered array
'modules' => [
'Home' => 'Home',
'Accounts' => 'Accounts',
'Contacts' => 'Contacts',
'Cases' => 'Cases',
'Bugs' => 'Bugs'
'accounts',
'bugs',
'cases',
'contacts',
'home',
]
],
'Activities' => [
3 => [
'name' => 'activities',
'labelKey' => 'LBL_TABGROUP_ACTIVITIES',
// Ordered array
'modules' => [
'Home' => 'Home',
'Calendar' => 'Calendar',
'Calls' => 'Calls',
'Meetings' => 'Meetings',
'Emails' => 'Emails',
'Tasks' => 'Tasks',
'Notes' => 'Notes'
'calendar',
'calls',
'emails',
'home',
'meetings',
'notes',
'tasks',
]
],
'Collaboration' => [
4 => [
'name' => 'collaboration',
'labelKey' => 'LBL_TABGROUP_COLLABORATION',
// Ordered array
'modules' => [
'Home' => 'Home',
'Emails' => 'Emails',
'Documents' => 'Documents',
'Project' => 'Projects'
'documents',
'emails',
'home',
'projects',
]
]
],
];
$this->assertSame(