From af43a9cf1dcece0d7f890f636d33b11ece4a4230 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 10 Oct 2023 16:02:52 +0200 Subject: [PATCH] fix(dropdownfield): display of username in Formcreator 2.4.2, user was displayed with first and last name --- inc/field/dropdownfield.class.php | 12 +++++++++--- tests/3-unit/PluginFormcreatorForm.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/inc/field/dropdownfield.class.php b/inc/field/dropdownfield.class.php index d93229f3c..5fb5f92cd 100644 --- a/inc/field/dropdownfield.class.php +++ b/inc/field/dropdownfield.class.php @@ -357,11 +357,17 @@ public function getRenderedHtml($domain, $canEdit = true): string { $item = new $itemtype(); $value = ''; if ($item->getFromDB($this->value)) { - $column = 'name'; + $value = $item->fields['name']; if ($item instanceof CommonTreeDropdown) { - $column = 'completename'; + $value = $item->fields['completename']; + } else { + /** @var CommonDBTM $item */ + switch ($item->getType()) { + case User::class: + $value = (new DbUtils())->getUserName($item->getID()); + break; + } } - $value = $item->fields[$column]; } return $value; diff --git a/tests/3-unit/PluginFormcreatorForm.php b/tests/3-unit/PluginFormcreatorForm.php index 6ecc8a538..9b14fae41 100644 --- a/tests/3-unit/PluginFormcreatorForm.php +++ b/tests/3-unit/PluginFormcreatorForm.php @@ -485,7 +485,7 @@ public function testCreateValidationNotification(User $requester, User $validato $form = $this->getForm([ 'name' => 'validation notification', - 'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER, + 'validation_required' => PluginFormcreatorForm_Validator::VALIDATION_USER, '_validator_users' => [$validator->getID()], ]); $this->getSection([