Skip to content

Commit 14f6824

Browse files
authored
WIP Fix(UI): fix UI (#1021)
* Fix(UI): fix UI * move tab renderer to twig * fix license * fix rector * fix
1 parent de37ab7 commit 14f6824

File tree

5 files changed

+99
-46
lines changed

5 files changed

+99
-46
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
9+
## ['UNRELEASED']
10+
11+
### Fixed
12+
13+
- Fix UI with GLPI 11
14+
- Fix `tab` container not displayed
15+
816
## [1.22.0] - 2025-09-30
917

1018
### Added

inc/container.class.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,13 +1240,12 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
12401240
if (!$item->isEntityAssign() || in_array($item->fields['entities_id'], $entities)) {
12411241
$display_condition = new PluginFieldsContainerDisplayCondition();
12421242
if ($display_condition->computeDisplayContainer($item, $data['id'])) {
1243-
$tabs_entries[$tab_name] = self::createTabEntry($data['label'], 0, null, PluginFieldsContainer::getIcon());
1243+
$tabs_entries[$data['id']] = self::createTabEntry($data['label'], 0, null, PluginFieldsContainer::getIcon());
12441244
}
12451245
}
12461246
}
12471247
}
12481248
}
1249-
12501249
return $tabs_entries;
12511250
}
12521251

@@ -1262,11 +1261,10 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
12621261

12631262
//retrieve container for current tab
12641263
$container = new self();
1265-
$found_c = $container->find(['type' => 'tab', 'name' => $tabnum, 'is_active' => 1]);
1266-
foreach ($found_c as $data) {
1267-
$dataitemtypes = json_decode($data['itemtypes']);
1264+
if ($container->getFromDB($tabnum)) {
1265+
$dataitemtypes = json_decode($container->fields['itemtypes']);
12681266
if (in_array(get_class($item), $dataitemtypes) != false) {
1269-
return PluginFieldsField::showForTabContainer($data['id'], $item);
1267+
return PluginFieldsField::showForTabContainer($container->fields['id'], $item);
12701268
}
12711269
}
12721270

inc/field.class.php

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,6 @@ public function showForm($ID, $options = [])
813813

814814
public static function showForTabContainer($c_id, $item)
815815
{
816-
/** @var array $CFG_GLPI */
817-
global $CFG_GLPI;
818-
819816
//profile restriction
820817
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id);
821818
if ($right < READ) {
@@ -826,22 +823,16 @@ public static function showForTabContainer($c_id, $item)
826823
//get fields for this container
827824
$field_obj = new self();
828825
$fields = $field_obj->find(['plugin_fields_containers_id' => $c_id, 'is_active' => 1], 'ranking');
829-
echo "<form method='POST' action='" . $CFG_GLPI['root_doc'] . "/plugins/fields/front/container.form.php'>";
830-
echo Html::hidden('plugin_fields_containers_id', ['value' => $c_id]);
831-
echo Html::hidden('items_id', ['value' => $item->getID()]);
832-
echo Html::hidden('itemtype', ['value' => $item->getType()]);
833-
echo "<table class='tab_cadre_fixe'>";
834-
echo self::prepareHtmlFields($fields, $item, $canedit);
835-
836-
if ($canedit) {
837-
echo "<tr><td class='tab_bg_2 center' colspan='4'>";
838-
echo "<input class='btn btn-primary' type='submit' name='update_fields_values' value=\"" .
839-
_sx('button', 'Save') . "\" class='submit'>";
840-
echo '</td></tr>';
841-
}
826+
$html_fields = self::prepareHtmlFields($fields, $item, $canedit);
827+
828+
//display fields as tab container
829+
TemplateRenderer::getInstance()->display('@fields/forms/tab_container.html.twig', [
830+
'canedit' => $canedit,
831+
'html_fields' => $html_fields,
832+
'item' => $item,
833+
'c_id' => $c_id,
834+
]);
842835

843-
echo '</table>';
844-
Html::closeForm();
845836

846837
return true;
847838
}
@@ -960,30 +951,25 @@ public static function showForTab($params)
960951
return;
961952
}
962953

954+
$class = match (true) {
955+
!($item instanceof CommonITILObject) && $item instanceof CommonDropdown => 'card-body row',
956+
// @phpstan-ignore-next-line -> Instanceof between CommonDBTM and CommonDropdown will always evaluate to false.
957+
!($item instanceof CommonITILObject) && !($item instanceof CommonDropdown) => 'card-body d-flex flex-wrap', // lign 969
958+
default => '',
959+
};
963960
$html_id = 'plugin_fields_container_' . mt_rand();
964-
if (str_contains($current_url, 'helpdesk.public.php')) {
965-
echo "<div id='{$html_id}' class='card-body row mx-0' style='border-top:0'>";
966-
echo "<div class='offset-md-1 col-md-8 col-xxl-6'>";
967-
$field_options = [
968-
'label_class' => 'col-lg-3',
969-
'input_class' => 'col-lg-9',
970-
];
971-
} else {
972-
echo "<div id='{$html_id}'>";
973-
}
961+
962+
echo "<div id='{$html_id}' class='" . $class . "'>";
974963
$display_condition = new PluginFieldsContainerDisplayCondition();
975964
if ($display_condition->computeDisplayContainer($item, $c_id)) {
976965
self::showDomContainer(
977966
$c_id,
978967
$item,
979968
$type,
980969
$subtype,
981-
$field_options ?? [],
970+
[],
982971
);
983972
}
984-
if (str_contains($current_url, 'helpdesk.public.php')) {
985-
echo '</div>';
986-
}
987973
echo '</div>';
988974

989975
//JS to trigger any change and check if container need to be display or not
@@ -1085,6 +1071,7 @@ public static function prepareHtmlFields(
10851071
$massiveaction = false,
10861072
$field_options = []
10871073
) {
1074+
10881075
if (empty($fields)) {
10891076
return false;
10901077
}

templates/fields.html.twig

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
{% import 'components/form/fields_macros.html.twig' as macros %}
3030

3131
{% set already_wrapped = item is instanceof('CommonITILObject') and container.fields['type'] == 'dom' %}
32+
{% set dropdown_item = item is instanceof('CommonDropdown') and container.fields['type'] == 'dom' %}
3233

33-
{% if not already_wrapped %}
34-
<div class="card-body d-flex flex-wrap">
35-
<div class="col-12 col-xxl-12 flex-column">
36-
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
37-
<div class="row flex-row align-items-start flex-grow-1">
38-
<div class="row flex-row">
34+
{% if not already_wrapped and not dropdown_item%}
35+
36+
{% set class = item.isNewItem() ? 'col-xxl-12' : 'col-xxl-9' %}
37+
<div class="col-12 {{ class }} flex-column">
38+
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
39+
<div class="row flex-row align-items-start flex-grow-1">
40+
<div class="row flex-row">
3941
{% endif %}
4042

4143
{% for field in fields %}
@@ -184,8 +186,8 @@
184186
{% endif %}
185187
{% endfor %}
186188

187-
{% if not already_wrapped %}
188-
</div>
189+
{% if not already_wrapped and not dropdown_item%}
190+
189191
</div>
190192
</div>
191193
</div>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{#
2+
# -------------------------------------------------------------------------
3+
# Fields plugin for GLPI
4+
# -------------------------------------------------------------------------
5+
#
6+
# LICENSE
7+
#
8+
# This file is part of Fields.
9+
#
10+
# Fields is free software; you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation; either version 2 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# Fields is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with Fields. If not, see <http://www.gnu.org/licenses/>.
22+
# -------------------------------------------------------------------------
23+
# @copyright Copyright (C) 2013-2023 by Fields plugin team.
24+
# @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
25+
# @link https://github.com/pluginsGLPI/fields
26+
# -------------------------------------------------------------------------
27+
#}
28+
29+
<div class="card-body d-flex flex-wrap">
30+
<div class="col-12 col-xxl-12 flex-column">
31+
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
32+
<div class="row flex-row align-items-start flex-grow-1" style="min-width: 0;">
33+
<div class="row flex-row">
34+
35+
{% if canedit %}
36+
<form method='POST' class='mt-5' action='/plugins/fields/front/container.form.php'>
37+
<input type="hidden" name="plugin_fields_containers_id" value="{{ c_id }}">
38+
<input type="hidden" name="items_id" value="{{ item.getID() }}">
39+
<input type="hidden" name="itemtype" value="{{ item.getType() }}">
40+
{% endif %}
41+
42+
{{ html_fields|raw }}
43+
44+
{% if canedit %}
45+
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
46+
<div class="card-body mt-3 mx-n2 border-top d-flex flex-row-reverse align-items-start flex-wrap">
47+
<button class="btn btn-primary me-2" type="submit" name="update_fields_values" value="1">
48+
<i class="ti ti-device-floppy"></i>
49+
<span>{{ _x('button', 'Save') }}</span>
50+
</button>
51+
</div>
52+
</form>
53+
{% endif %}
54+
</div>
55+
</div>
56+
</div>
57+
</div>
58+
</div>

0 commit comments

Comments
 (0)