Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## ['UNRELEASED']

### Fixed

- Fix UI with GLPI 11
- Fix `tab` container not displayed

## [1.22.0] - 2025-09-30

### Added
Expand Down
10 changes: 4 additions & 6 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,13 +1240,12 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
if (!$item->isEntityAssign() || in_array($item->fields['entities_id'], $entities)) {
$display_condition = new PluginFieldsContainerDisplayCondition();
if ($display_condition->computeDisplayContainer($item, $data['id'])) {
$tabs_entries[$tab_name] = self::createTabEntry($data['label'], 0, null, PluginFieldsContainer::getIcon());
$tabs_entries[$data['id']] = self::createTabEntry($data['label'], 0, null, PluginFieldsContainer::getIcon());
}
}
}
}
}

return $tabs_entries;
}

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

//retrieve container for current tab
$container = new self();
$found_c = $container->find(['type' => 'tab', 'name' => $tabnum, 'is_active' => 1]);
foreach ($found_c as $data) {
$dataitemtypes = json_decode($data['itemtypes']);
if ($container->getFromDB($tabnum)) {
$dataitemtypes = json_decode($container->fields['itemtypes']);
if (in_array(get_class($item), $dataitemtypes) != false) {
return PluginFieldsField::showForTabContainer($data['id'], $item);
return PluginFieldsField::showForTabContainer($container->fields['id'], $item);
}
}

Expand Down
51 changes: 19 additions & 32 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,6 @@ public function showForm($ID, $options = [])

public static function showForTabContainer($c_id, $item)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

//profile restriction
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id);
if ($right < READ) {
Expand All @@ -826,22 +823,16 @@ public static function showForTabContainer($c_id, $item)
//get fields for this container
$field_obj = new self();
$fields = $field_obj->find(['plugin_fields_containers_id' => $c_id, 'is_active' => 1], 'ranking');
echo "<form method='POST' action='" . $CFG_GLPI['root_doc'] . "/plugins/fields/front/container.form.php'>";
echo Html::hidden('plugin_fields_containers_id', ['value' => $c_id]);
echo Html::hidden('items_id', ['value' => $item->getID()]);
echo Html::hidden('itemtype', ['value' => $item->getType()]);
echo "<table class='tab_cadre_fixe'>";
echo self::prepareHtmlFields($fields, $item, $canedit);

if ($canedit) {
echo "<tr><td class='tab_bg_2 center' colspan='4'>";
echo "<input class='btn btn-primary' type='submit' name='update_fields_values' value=\"" .
_sx('button', 'Save') . "\" class='submit'>";
echo '</td></tr>';
}
$html_fields = self::prepareHtmlFields($fields, $item, $canedit);

//display fields as tab container
TemplateRenderer::getInstance()->display('@fields/forms/tab_container.html.twig', [
'canedit' => $canedit,
'html_fields' => $html_fields,
'item' => $item,
'c_id' => $c_id,
]);

echo '</table>';
Html::closeForm();

return true;
}
Expand Down Expand Up @@ -960,30 +951,25 @@ public static function showForTab($params)
return;
}

$class = match (true) {
!($item instanceof CommonITILObject) && $item instanceof CommonDropdown => 'card-body row',
// @phpstan-ignore-next-line -> Instanceof between CommonDBTM and CommonDropdown will always evaluate to false.
!($item instanceof CommonITILObject) && !($item instanceof CommonDropdown) => 'card-body d-flex flex-wrap', // lign 969
default => '',
};
$html_id = 'plugin_fields_container_' . mt_rand();
if (str_contains($current_url, 'helpdesk.public.php')) {
echo "<div id='{$html_id}' class='card-body row mx-0' style='border-top:0'>";
echo "<div class='offset-md-1 col-md-8 col-xxl-6'>";
$field_options = [
'label_class' => 'col-lg-3',
'input_class' => 'col-lg-9',
];
} else {
echo "<div id='{$html_id}'>";
}

echo "<div id='{$html_id}' class='" . $class . "'>";
$display_condition = new PluginFieldsContainerDisplayCondition();
if ($display_condition->computeDisplayContainer($item, $c_id)) {
self::showDomContainer(
$c_id,
$item,
$type,
$subtype,
$field_options ?? [],
[],
);
}
if (str_contains($current_url, 'helpdesk.public.php')) {
echo '</div>';
}
echo '</div>';

//JS to trigger any change and check if container need to be display or not
Expand Down Expand Up @@ -1085,6 +1071,7 @@ public static function prepareHtmlFields(
$massiveaction = false,
$field_options = []
) {

if (empty($fields)) {
return false;
}
Expand Down
18 changes: 10 additions & 8 deletions templates/fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
{% import 'components/form/fields_macros.html.twig' as macros %}

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

{% if not already_wrapped %}
<div class="card-body d-flex flex-wrap">
<div class="col-12 col-xxl-12 flex-column">
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
<div class="row flex-row align-items-start flex-grow-1">
<div class="row flex-row">
{% if not already_wrapped and not dropdown_item%}

{% set class = item.isNewItem() ? 'col-xxl-12' : 'col-xxl-9' %}
<div class="col-12 {{ class }} flex-column">
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
<div class="row flex-row align-items-start flex-grow-1">
<div class="row flex-row">
{% endif %}

{% for field in fields %}
Expand Down Expand Up @@ -184,8 +186,8 @@
{% endif %}
{% endfor %}

{% if not already_wrapped %}
</div>
{% if not already_wrapped and not dropdown_item%}

</div>
</div>
</div>
Expand Down
58 changes: 58 additions & 0 deletions templates/forms/tab_container.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{#
# -------------------------------------------------------------------------
# Fields plugin for GLPI
# -------------------------------------------------------------------------
#
# LICENSE
#
# This file is part of Fields.
#
# Fields 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 2 of the License, or
# (at your option) any later version.
#
# Fields 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 Fields. If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------------
# @copyright Copyright (C) 2013-2023 by Fields plugin team.
# @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
# @link https://github.com/pluginsGLPI/fields
# -------------------------------------------------------------------------
#}

<div class="card-body d-flex flex-wrap">
<div class="col-12 col-xxl-12 flex-column">
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
<div class="row flex-row align-items-start flex-grow-1" style="min-width: 0;">
<div class="row flex-row">

{% if canedit %}
<form method='POST' class='mt-5' action='/plugins/fields/front/container.form.php'>
<input type="hidden" name="plugin_fields_containers_id" value="{{ c_id }}">
<input type="hidden" name="items_id" value="{{ item.getID() }}">
<input type="hidden" name="itemtype" value="{{ item.getType() }}">
{% endif %}

{{ html_fields|raw }}

{% if canedit %}
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
<div class="card-body mt-3 mx-n2 border-top d-flex flex-row-reverse align-items-start flex-wrap">
<button class="btn btn-primary me-2" type="submit" name="update_fields_values" value="1">
<i class="ti ti-device-floppy"></i>
<span>{{ _x('button', 'Save') }}</span>
</button>
</div>
</form>
{% endif %}
</div>
</div>
</div>
</div>
</div>