From a6407257dd2752b6f2931f43b0c4bcdf9b1ffe05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 12 Apr 2022 11:11:26 +0200 Subject: [PATCH 1/4] Allow to view tabs in module builder --- htdocs/langs/en_US/modulebuilder.lang | 5 +- htdocs/modulebuilder/index.php | 127 ++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 7ba539d3bd4..6376024ea0b 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -143,4 +143,7 @@ AsciiToHtmlConverter=Ascii to HTML converter AsciiToPdfConverter=Ascii to PDF converter TableNotEmptyDropCanceled=Table not empty. Drop has been canceled. ModuleBuilderNotAllowed=The module builder is available but not allowed to your user. -ImportExportProfiles=Import and export profiles \ No newline at end of file +ImportExportProfiles=Import and export profiles +ListOfTabsEntries=List of tab entries +TabsDefDesc= Define here the tabs provided by your module +TabsDefDescTooltip=The tabs provided by your module/application are defined into the array $this->tabs into the module descriptor file. You can edit manually this file or use the embedded editor. diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 82567e05fac..16671ddf137 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1931,6 +1931,11 @@ if ($module == 'initmodule') { $head2[$h][2] = 'permissions'; $h++; + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=tabs&module='.$module.($forceddirread ? '@'.$dirread : ''); + $head2[$h][1] = $langs->trans("Tabs"); + $head2[$h][2] = 'tabs'; + $h++; + $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : ''); $head2[$h][1] = $langs->trans("Menus"); $head2[$h][2] = 'menus'; @@ -3902,6 +3907,128 @@ if ($module == 'initmodule') { print ''; } + if ($tab == 'tabs') { + $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + + $tabs = $moduleobj->tabs; + + if ($action != 'editfile' || empty($file)) { + print ''; + $htmlhelp = $langs->trans("TabsDefDescTooltip", '{s1}'); + $htmlhelp = str_replace('{s1}', ''.$langs->trans('Setup').' - '.$langs->trans('Tabs').'', $htmlhelp); + print $form->textwithpicto($langs->trans("TabsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'
'; + print '
'; + print '
'; + + print ' '.$langs->trans("DescriptorFile").' : '.$pathtofile.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + + print '
'; + print load_fiche_titre($langs->trans("ListOfTabsEntries"), '', ''); + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'; + print ''; + + print ''; + print_liste_field_titre("ObjectType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Tab", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("LangFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Path", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print "\n"; + + if (count($tabs)) { + foreach ($tabs as $tab) { + $parts = explode(':', $tab['data']); + + $objectType = $parts[0]; + $tabName = $parts[1]; + $tabTitle = isset($parts[2]) ? $parts[2] : ''; + $langFile = isset($parts[3]) ? $parts[3] : ''; + $condition = isset($parts[4]) ? $parts[4] : ''; + $path = isset($parts[5]) ? $parts[5] : ''; + + // If we want to remove the tab, then the format is 'tabname:optionalcondition' + // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab + if ($tabName[0] === '-') { + $tabTitle = ''; + $condition = isset($parts[2]) ? $parts[2] : ''; + } + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + } + } else { + print ''; + } + + print '
'; + print dol_escape_htmltag($parts[0]); + print ''; + if ($tabName[0] === "+") + print '' . dol_escape_htmltag($tabName) . ''; + else + print '' . dol_escape_htmltag($tabName) . ''; + print ''; + print dol_escape_htmltag($tabTitle); + print ''; + print dol_escape_htmltag($langFile); + print ''; + print dol_escape_htmltag($condition); + print ''; + print dol_escape_htmltag($path); + print '
'.$langs->trans("None").'
'; + print '
'; + + print '
'; + } else { + $fullpathoffile = dol_buildpath($file, 0); + + $content = file_get_contents($fullpathoffile); + + // New module + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%'); + print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html')); + print '
'; + print '
'; + print ''; + print '   '; + print ''; + print '
'; + + print '
'; + } + } + if ($tab != 'description') { print dol_get_fiche_end(); } From 25a851ac70f70df00e5408e344b26b3b5a979c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 12 Apr 2022 11:12:43 +0200 Subject: [PATCH 2/4] Fix translation --- htdocs/langs/en_US/modulebuilder.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 6376024ea0b..5544c2b932a 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -145,5 +145,5 @@ TableNotEmptyDropCanceled=Table not empty. Drop has been canceled. ModuleBuilderNotAllowed=The module builder is available but not allowed to your user. ImportExportProfiles=Import and export profiles ListOfTabsEntries=List of tab entries -TabsDefDesc= Define here the tabs provided by your module +TabsDefDesc=Define here the tabs provided by your module TabsDefDescTooltip=The tabs provided by your module/application are defined into the array $this->tabs into the module descriptor file. You can edit manually this file or use the embedded editor. From a747f574b3dc5144e9e695f1ec42d19935ca1ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 12 Apr 2022 11:15:40 +0200 Subject: [PATCH 3/4] Improve comment --- htdocs/modulebuilder/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 16671ddf137..14385864b6b 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -3957,7 +3957,7 @@ if ($module == 'initmodule') { $condition = isset($parts[4]) ? $parts[4] : ''; $path = isset($parts[5]) ? $parts[5] : ''; - // If we want to remove the tab, then the format is 'tabname:optionalcondition' + // If we want to remove the tab, then the format is 'objecttype:tabname:optionalcondition' // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab if ($tabName[0] === '-') { $tabTitle = ''; From 752cc6f4a7adbc4fd791ef6229ce28feb5c8569d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 12 Apr 2022 11:17:24 +0200 Subject: [PATCH 4/4] Lint source code --- htdocs/modulebuilder/index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 14385864b6b..937ef6d83fb 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -3971,10 +3971,11 @@ if ($module == 'initmodule') { print ''; print ''; - if ($tabName[0] === "+") + if ($tabName[0] === "+") { print '' . dol_escape_htmltag($tabName) . ''; - else + } else { print '' . dol_escape_htmltag($tabName) . ''; + } print ''; print '';