Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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]

### Added

- Add a "Conditions to hide field" tab on containers, to hide a single field of a block based on a condition on the main object, instead of hiding the whole block.

## [1.24.4] - 2026-08-06

### Fixed
Expand Down
57 changes: 57 additions & 0 deletions ajax/field_display_condition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* -------------------------------------------------------------------------
* 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
* -------------------------------------------------------------------------
*/
Session::checkRight('config', READ);

if (isset($_GET['action'])) {
if ($_GET['action'] === 'get_add_form') {
$field_display_condition = new PluginFieldsFieldDisplayCondition();
$field_display_condition->showForm(0, $_GET);
} elseif ($_GET['action'] === 'get_edit_form') {
$field_display_condition = new PluginFieldsFieldDisplayCondition();
$field_display_condition->getFromDB($_GET['id']);
$field_display_condition->showForm($_GET['id'], $_GET);
}
} elseif (isset($_POST['action'])) {
if ($_POST['action'] === 'get_itemtype_so') {
if (isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
echo PluginFieldsContainerDisplayCondition::showItemtypeFieldForm($_POST['itemtype']);
} else {
echo '';
}
} elseif ($_POST['action'] === 'get_condition_switch_so') {
if (isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) {
echo PluginFieldsContainerDisplayCondition::showSearchOptionCondition($_POST['search_option_id'], $_POST['itemtype']);
} else {
echo '';
}
}
} else {
throw new RuntimeException('Invalid request', 400);
}
50 changes: 50 additions & 0 deletions front/fielddisplaycondition.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* -------------------------------------------------------------------------
* 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
* -------------------------------------------------------------------------
*/

Session::checkRight('config', READ);

$field_display_condition = new PluginFieldsFieldDisplayCondition();
if (isset($_POST['add'])) {
$field_display_condition->check(-1, CREATE, $_POST);
$field_display_condition->add($_POST);
Html::back();
} elseif (isset($_POST['update'])) {
$field_display_condition->check($_POST['id'], UPDATE);
$field_display_condition->update($_POST);
Html::back();
} elseif (isset($_POST['delete'])) {
$field_display_condition->check($_POST['id'], PURGE);
$field_display_condition->delete([
'id' => $_POST['id'],
]);
Html::back();
}

Html::back();
2 changes: 2 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function plugin_fields_install()
$classesToInstall = [
PluginFieldsContainer::class,
PluginFieldsContainerDisplayCondition::class,
PluginFieldsFieldDisplayCondition::class,
PluginFieldsDropdown::class,
PluginFieldsField::class,
PluginFieldsLabelTranslation::class,
Expand Down Expand Up @@ -137,6 +138,7 @@ function plugin_fields_uninstall()
'PluginFieldsProfile',
'PluginFieldsStatusOverride',
'PluginFieldsContainerDisplayCondition',
'PluginFieldsFieldDisplayCondition',
];

foreach ($classesToUninstall as $class) {
Expand Down
1 change: 1 addition & 0 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ public function defineTabs($options = [])
$this->addStandardTab('PluginFieldsStatusOverride', $ong, $options);
$this->addStandardTab('PluginFieldsProfile', $ong, $options);
$this->addStandardTab('PluginFieldsContainerDisplayCondition', $ong, $options);
$this->addStandardTab('PluginFieldsFieldDisplayCondition', $ong, $options);
$this->addStandardTab('PluginFieldsLabelTranslation', $ong, $options);

return $ong;
Expand Down
2 changes: 1 addition & 1 deletion inc/containerdisplaycondition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static function getDisplayConditionForContainer(int $container_id): array
return $conditions;
}

private function getItemtypesForContainer(int $container_id): array
public function getItemtypesForContainer(int $container_id): array
{
/** @var DBmysql $DB */
global $DB;
Expand Down
15 changes: 15 additions & 0 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,21 @@ public static function prepareHtmlFields(
return false;
}

//remove fields that must be hidden for this item, based on the
//"conditions to hide field" configured on the container
$displayCondition = new PluginFieldsFieldDisplayCondition();
$fields = array_filter($fields, static function ($field) use ($displayCondition, $item) {
return $displayCondition->computeDisplayField(
$item,
$field['plugin_fields_containers_id'],
$field['id'],
);
});

if (empty($fields)) {
return false;
}

// check if current profile can edit fields
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $container_obj->getID());
if ($right < READ) {
Expand Down
Loading
Loading