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
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]

### Fixed

- 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

### Fixed
Expand Down
8 changes: 6 additions & 2 deletions inc/containerdisplaycondition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ 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 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,
is_a($twig_params['dropdown_itemtype'], CommonTreeDropdown::class, true),
Expand Down Expand Up @@ -324,7 +326,9 @@ 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 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);
if ($dropdown->getFromDB($value)) {
Expand Down
84 changes: 84 additions & 0 deletions tests/Units/ContainerDisplayConditionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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
* -------------------------------------------------------------------------
*/

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());
}
}