From d4c0826c1a7c14cea25f3104bec21cf109bba751 Mon Sep 17 00:00:00 2001 From: Herafia Date: Mon, 27 Jul 2026 13:45:11 +0200 Subject: [PATCH 1/3] fix handle native glpi dropdown types when binding additional fields to form destination --- inc/destinationfield.class.php | 4 ++-- inc/questiontype.class.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/destinationfield.class.php b/inc/destinationfield.class.php index 3cc553cc..b55be89c 100644 --- a/inc/destinationfield.class.php +++ b/inc/destinationfield.class.php @@ -134,8 +134,8 @@ public function applyConfiguratedValueToInputUsingAnswers( if ($field->fields['type'] == 'glpi_item') { $input[sprintf('itemtype_%s', $field_name)] = $answer->getRawAnswer()['itemtype']; $input[sprintf('items_id_%s', $field_name)] = $answer->getRawAnswer()['items_id']; - } elseif ($field->fields['type'] == 'dropdown') { - $raw_id = (int) $answer->getRawAnswer()['items_id']; + } elseif (str_starts_with((string) $field->fields['type'], 'dropdown')) { + $raw_id = (int) ($answer->getRawAnswer()['items_id'] ?? 0); $input[$field_name] = ($raw_id > 0) ? $raw_id : null; } else { $input[$field_name] = $value ?? $answer->getRawAnswer(); diff --git a/inc/questiontype.class.php b/inc/questiontype.class.php index e40963d0..a38daf1b 100644 --- a/inc/questiontype.class.php +++ b/inc/questiontype.class.php @@ -248,7 +248,7 @@ public function formatRawAnswer(mixed $answer, Question $question): string $names = []; foreach ($answer as $items_id) { - $item = $itemtype::getById($items_id); + $item = $itemtype::getById((int) $items_id); if ($item) { $names[] = $item->fields['name']; } From 00db1757e7badf78af8e61a8880668134c3f1a41 Mon Sep 17 00:00:00 2001 From: Herafia Date: Mon, 27 Jul 2026 13:55:55 +0200 Subject: [PATCH 2/3] CHANGELOG + test --- CHANGELOG.md | 1 + tests/Units/FieldDestinationFieldTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be0ec1ad..874232d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix item creation with null value for mandatory fields - Fix search crash when two containers share a dropdown field with the same name. +- fix handle native GLPI dropdown types when binding additional fields to form destination ## [1.24.2] - 2026-06-30 diff --git a/tests/Units/FieldDestinationFieldTest.php b/tests/Units/FieldDestinationFieldTest.php index 316169a8..7a6f5e89 100644 --- a/tests/Units/FieldDestinationFieldTest.php +++ b/tests/Units/FieldDestinationFieldTest.php @@ -236,7 +236,12 @@ public function testDestinationWithLocationAdditonalFields(): void form: $form, config: new SimpleValueConfig(1), answers: [ - "Location Field" => $location->getID(), + // The end user template submits dropdowns as an array + // containing the selected itemtype and items_id. + "Location Field" => [ + 'itemtype' => Location::class, + 'items_id' => $location->getID(), + ], ], expected_field_values: [ Ticket::class => [ From a05df29d5ab07f210e0e9b7a7afb4174f825e8e2 Mon Sep 17 00:00:00 2001 From: "Romain B." <8530352+Rom1-B@users.noreply.github.com> Date: Mon, 27 Jul 2026 15:59:54 +0200 Subject: [PATCH 3/3] Apply suggestion from @Rom1-B --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 874232d5..39363e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix item creation with null value for mandatory fields - Fix search crash when two containers share a dropdown field with the same name. -- fix handle native GLPI dropdown types when binding additional fields to form destination +- Fix handle native GLPI dropdown types when binding additional fields to form destination ## [1.24.2] - 2026-06-30