diff --git a/CHANGELOG.md b/CHANGELOG.md index be0ec1ad..39363e25 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/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']; } 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 => [