NEW: Migrate category extrafields admin pages to the unified page

This commit is contained in:
Frédéric FRANCE 2026-08-11 19:30:44 +02:00
parent f55ae4b889
commit 1df4561a61
No known key found for this signature in database
GPG key ID: C06E4A9656127239
4 changed files with 24 additions and 235 deletions

View file

@ -1,105 +0,0 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/categories/admin/categorie_extrafields.php
* \ingroup societe
* \brief Page to setup extra fields of category
*/
// Load Dolibarr environment
require '../../main.inc.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var ExtraFields $extrafields
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
// Load translation files required by the page
$langs->loadLangs(array('categories', 'admin'));
$form = new Form($db);
// List of supported format
$type2label = ExtraFields::getListOfTypesLabels();
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'categorie'; //Must be the $element of the class that manage extrafield
if (!$user->admin) {
accessforbidden();
}
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
$textobject = $langs->transnoentitiesnoconv("Categories");
$help_url = 'EN:Module Categories|FR:Module Catégories|ES:Módulo Categorías|DE:Modul_Kategorien';
llxHeader('', $langs->trans("Categories"), $help_url);
$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
print load_fiche_titre($langs->trans("CategoriesSetup"), $linkback, 'title_setup');
$head = categoriesadmin_prepare_head();
print dol_get_fiche_head($head, 'attributes_categories', $langs->trans("Categories"), -1, 'category');
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
print dol_get_fiche_end();
// Creation of an optional field
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
// Edition of an optional field
if ($action == 'edit' && !empty($attrname)) {
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View file

@ -1,128 +0,0 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file admin/categorie_lang_extrafields.php
* \ingroup categorie
* \brief Page to setup extra fields of categorie lang
*/
// Load Dolibarr environment
require '../../main.inc.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var ExtraFields $extrafields
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'categories'));
$form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'categorie_lang'; // Must be the $table_element of the class that manage extrafield
if (!$user->admin) {
accessforbidden();
}
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
$textobject = $langs->transnoentitiesnoconv("Category");
$help_url = '';
$page_name = "CategoriesTranslationsExtrafields";
llxHeader('', $langs->trans($page_name), $help_url);
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
$head = categoriesadmin_prepare_head();
print dol_get_fiche_head($head, 'translationAttributes', $langs->trans($page_name), -1, 'categorie');
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
print dol_get_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit') {
print '<div class="tabsAction">';
print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action=create">'.$langs->trans("NewAttribute").'</a>';
print "</div>";
}
/*
* Creation of an optional field
*/
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
/*
* Edition of an optional field
*/
if ($action == 'edit' && !empty($attrname)) {
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View file

@ -581,5 +581,27 @@ function getExtrafieldsAdminMap()
'helpurl' => '', 'helpurl' => '',
'langs' => array('workstation', 'admin'), 'langs' => array('workstation', 'admin'),
), ),
'categorie' => array(
'headfunction' => 'categoriesadmin_prepare_head',
'headfile' => 'core/lib/categories.lib.php',
'tabid' => 'attributes_categories',
'headlabel' => 'Categories',
'textobject' => 'Categories',
'headpicto' => 'category',
'title' => 'Categories',
'helpurl' => 'EN:Module Categories|FR:Module Catégories|ES:Módulo Categorías|DE:Modul_Kategorien',
'langs' => array('categories', 'admin'),
),
'categorie_lang' => array(
'headfunction' => 'categoriesadmin_prepare_head',
'headfile' => 'core/lib/categories.lib.php',
'tabid' => 'translationAttributes',
'headlabel' => 'CategoriesTranslationsExtrafields',
'textobject' => 'Category',
'headpicto' => 'categorie',
'title' => 'CategoriesTranslationsExtrafields',
'helpurl' => '',
'langs' => array('admin', 'categories'),
),
); );
} }

View file

@ -100,7 +100,7 @@ function categoriesadmin_prepare_head()
$head[$h][2] = 'setup'; $head[$h][2] = 'setup';
$h++; $h++;
$head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/categories/admin/categorie_extrafields.php'); $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/extrafields.php', array('elementtype' => 'categorie'));
$head[$h][1] = $langs->trans("ExtraFieldsCategories"); $head[$h][1] = $langs->trans("ExtraFieldsCategories");
$nbExtrafields = $extrafields->attributes['categorie']['count']; $nbExtrafields = $extrafields->attributes['categorie']['count'];
if ($nbExtrafields > 0) { if ($nbExtrafields > 0) {
@ -111,7 +111,7 @@ function categoriesadmin_prepare_head()
// Multilangs Extrafields // Multilangs Extrafields
if (getDolGlobalInt('MAIN_MULTILANGS')) { if (getDolGlobalInt('MAIN_MULTILANGS')) {
$head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/categories/admin/categorie_lang_extrafields.php'); $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/extrafields.php', array('elementtype' => 'categorie_lang'));
$head[$h][1] = $langs->trans("CategoriesTranslationsExtrafields"); $head[$h][1] = $langs->trans("CategoriesTranslationsExtrafields");
$nbExtrafields = isset($extrafields->attributes['categorie_lang']['count']) ? $extrafields->attributes['categorie_lang']['count'] : 0; $nbExtrafields = isset($extrafields->attributes['categorie_lang']['count']) ? $extrafields->attributes['categorie_lang']['count'] : 0;
if ($nbExtrafields > 0) { if ($nbExtrafields > 0) {