From 65130845c3ea250e894116f11153557fbcc1f3f6 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Tue, 4 Aug 2026 16:37:07 +0200 Subject: [PATCH 1/6] fix(45552): An error when trying to set the display conditions of a block on a custom asset --- inc/containerdisplaycondition.class.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index ae621035..2ce0accd 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -275,7 +275,13 @@ public static function showSearchOptionCondition($searchoption_id, $itemtype, ?s if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) { $twig_params['is_dropdown'] = true; - $twig_params['dropdown_itemtype'] = getItemTypeForTable($so['table']); + //No need to call for getItemForItemType if we are in the case of a custom asset + if ($so['table'] == 'glpi_assets_assettypes') { + $twig_params['dropdown_itemtype'] = $so['itemtype']; + } else { + $twig_params['dropdown_itemtype'] = getItemTypeForTable($so['table']); + } + $twig_params['list_conditions'] = self::getComparisonOperators( true, is_a($twig_params['dropdown_itemtype'], CommonTreeDropdown::class, true), @@ -324,7 +330,13 @@ public static function getRawValue($searchoption_id, $itemtype, $value) $raw_value = ''; if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) { - $dropdown_itemtype = getItemTypeForTable($so['table']); + //No need to call for getItemForItemType if we are in the case of a custom asset + if ($so['table'] == 'glpi_assets_assettypes') { + $dropdown_itemtype = $so['itemtype']; + } else { + $dropdown_itemtype = getItemTypeForTable($so['table']); + } + $dbu = new DbUtils(); $dropdown = $dbu->getItemForItemtype($dropdown_itemtype); if ($dropdown->getFromDB($value)) { From 22a28e11ed5aefb5655c49bbe6c31c9400e018c9 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Wed, 5 Aug 2026 10:25:29 +0200 Subject: [PATCH 2/6] chore(45552): Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd3c885..e0842859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] + +### Fixed + +- Fix a an error displaying on the UI when trying to create a bloc display condition based on "Type" or "Model" fields for custom assets + ## [1.24.3] - 2026-07-30 ### Fixed From 7e4b8557d86f5b6fc10b7d4a6f88cf94d31d1bb6 Mon Sep 17 00:00:00 2001 From: Julien DURAND Date: Wed, 5 Aug 2026 11:39:37 +0200 Subject: [PATCH 3/6] Update inc/containerdisplaycondition.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/containerdisplaycondition.class.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index 2ce0accd..0c8d6bc1 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -275,12 +275,8 @@ public static function showSearchOptionCondition($searchoption_id, $itemtype, ?s if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) { $twig_params['is_dropdown'] = true; - //No need to call for getItemForItemType if we are in the case of a custom asset - if ($so['table'] == 'glpi_assets_assettypes') { - $twig_params['dropdown_itemtype'] = $so['itemtype']; - } else { - $twig_params['dropdown_itemtype'] = getItemTypeForTable($so['table']); - } + //No need to call getItemTypeForTable if we are in the case of a custom asset + $twig_params['dropdown_itemtype'] = $so['itemtype'] ?? getItemTypeForTable($so['table']); $twig_params['list_conditions'] = self::getComparisonOperators( true, From 120f28e0d9b2d890641d7a6c03b839509e4acd54 Mon Sep 17 00:00:00 2001 From: Julien DURAND Date: Wed, 5 Aug 2026 11:39:48 +0200 Subject: [PATCH 4/6] Update inc/containerdisplaycondition.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/containerdisplaycondition.class.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index 0c8d6bc1..8c87b234 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -326,12 +326,8 @@ public static function getRawValue($searchoption_id, $itemtype, $value) $raw_value = ''; if ($so['datatype'] == 'dropdown' || ($so['datatype'] == 'itemlink' && $so['table'] !== $itemtypetable)) { - //No need to call for getItemForItemType if we are in the case of a custom asset - if ($so['table'] == 'glpi_assets_assettypes') { - $dropdown_itemtype = $so['itemtype']; - } else { - $dropdown_itemtype = getItemTypeForTable($so['table']); - } + //No need to call getItemTypeForTable if we are in the case of a custom asset + $dropdown_itemtype = $so['itemtype'] ?? getItemTypeForTable($so['table']); $dbu = new DbUtils(); $dropdown = $dbu->getItemForItemtype($dropdown_itemtype); From 9f722ca139e7942545b5d6f11a5580d74ea12513 Mon Sep 17 00:00:00 2001 From: Julien DURAND Date: Wed, 5 Aug 2026 11:40:01 +0200 Subject: [PATCH 5/6] Update CHANGELOG.md Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0842859..bf15da11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed -- Fix a an error displaying on the UI when trying to create a bloc display condition based on "Type" or "Model" fields for custom assets +- Fix an error displayed on the UI when trying to create a bloc display condition based on "Type" or "Model" fields for custom assets ## [1.24.3] - 2026-07-30 From a2c76faacf3ef211019d34e10f77787b4c858710 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Wed, 5 Aug 2026 11:44:26 +0200 Subject: [PATCH 6/6] chore(45552): Add unit test --- tests/Units/ContainerDisplayConditionTest.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/Units/ContainerDisplayConditionTest.php diff --git a/tests/Units/ContainerDisplayConditionTest.php b/tests/Units/ContainerDisplayConditionTest.php new file mode 100644 index 00000000..ee25d270 --- /dev/null +++ b/tests/Units/ContainerDisplayConditionTest.php @@ -0,0 +1,84 @@ +. + * ------------------------------------------------------------------------- + * @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 + * ------------------------------------------------------------------------- + */ + +declare(strict_types=1); + +namespace GlpiPlugin\Field\Tests\Units; + +use Glpi\Tests\DbTestCase; +use Glpi\Tests\GLPITestCase; +use PluginFieldsContainerDisplayCondition; +use Search; + +final class ContainerDisplayConditionTest extends DbTestCase +{ + public function setUp(): void + { + GLPITestCase::setUp(); + $this->login(); + } + + public function tearDown(): void + { + GLPITestCase::tearDown(); + } + + public function testGetRawValueOnCustomAssetTypeAndModel(): void + { + $definition = $this->initAssetDefinition(); + $asset_class = $definition->getAssetClassName(); + + $type = $this->createItem($definition->getAssetTypeClassName(), ['name' => 'Laptop']); + $model = $this->createItem($definition->getAssetModelClassName(), ['name' => 'ProBook']); + + $type_table = $definition->getAssetTypeClassName()::getTable(); + $model_table = $definition->getAssetModelClassName()::getTable(); + + $type_so_id = null; + $model_so_id = null; + foreach (Search::getOptions($asset_class) as $so_id => $so) { + if (($so['table'] ?? null) === $type_table) { + $type_so_id = $so_id; + } + + if (($so['table'] ?? null) === $model_table) { + $model_so_id = $so_id; + } + } + + ob_start(); + PluginFieldsContainerDisplayCondition::getRawValue($type_so_id, $asset_class, $type->getID()); + $this->assertSame('Laptop', ob_get_clean()); + + ob_start(); + PluginFieldsContainerDisplayCondition::getRawValue($model_so_id, $asset_class, $model->getID()); + $this->assertSame('ProBook', ob_get_clean()); + } +}