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
14 changes: 14 additions & 0 deletions src/Glpi/Form/QuestionType/QuestionTypeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
use CartridgeItem;
use Cluster;
use CommonDBTM;
use CommonDropdown;
use CommonTreeDropdown;
use ConsumableItem;
use Datacenter;
use DbUtils;
use Dropdown;
use DropdownTranslation;
use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\JsonFieldInterface;
use Glpi\Form\Category;
Expand Down Expand Up @@ -416,6 +418,18 @@ public function formatRawAnswer(mixed $answer, Question $question): string
? $item->fields['completename']
: $item->getFriendlyName();

// The ticket content is frozen at submission time, so the value must be
// resolved in the requester language here. Conditions are deliberately
// left untranslated: they must compare against the source value.
if ($item instanceof CommonDropdown) {
$name = DropdownTranslation::getTranslatedValue(
$item->getID(),
$item::class,
$item instanceof CommonTreeDropdown ? 'completename' : 'name',
value: $name
);
}

// Append additional fields to match what is displayed in renderEndUserTemplate.
$itemtype = $answer['itemtype'];
$extra_parts = [];
Expand Down
52 changes: 52 additions & 0 deletions tests/functional/Glpi/Form/QuestionType/QuestionTypeItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

use Computer;
use Contact;
use DropdownTranslation;
use Glpi\Form\Question;
use Glpi\Form\QuestionType\QuestionTypeItem;
use Glpi\Form\QuestionType\QuestionTypeItemDefaultValueConfig;
Expand Down Expand Up @@ -453,4 +454,55 @@ public function testFormatRawAnswer(callable $setup): void

$this->assertEquals($case['expected'], $result);
}

/**
* Non-regression test for #25249.
*
* The generated ticket content is frozen at submission time, so the item
* name has to be resolved in the requester language at that moment. Before
* the fix, formatRawAnswer() read the raw completename column and the
* answer was stored in the source language whatever the requester used.
*/
public function testFormatRawAnswerUsesDropdownTranslation(): void
{
$this->login();

$parent = $this->createItem(Location::class, [
'name' => 'Head office',
'entities_id' => $this->getTestRootEntity(true),
]);
$child = $this->createItem(Location::class, [
'name' => 'Meeting room',
'locations_id' => $parent->getID(),
'entities_id' => $this->getTestRootEntity(true),
]);

$this->createItem(DropdownTranslation::class, [
'items_id' => $child->getID(),
'itemtype' => Location::class,
'language' => 'fr_FR',
'field' => 'completename',
'value' => 'Siège social > Salle de réunion',
]);

// The translation cache is built at login, so the user must be logged
// in after the translation exists.
$this->createItem(User::class, [
'name' => 'fr_FR',
'language' => 'fr_FR',
'_entities_id' => $this->getTestRootEntity(true),
'_profiles_id' => 1,
]);
$this->login('fr_FR');

$result = (new QuestionTypeItem())->formatRawAnswer(
[
'itemtype' => Location::class,
'items_id' => $child->getID(),
],
new Question()
);

$this->assertEquals('Siège social > Salle de réunion', $result);
}
}
Loading