From 49f8fc0749d496109b1cd06e2271126dee7bb0f7 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 7 Jun 2023 08:53:29 +0200 Subject: [PATCH] fix(dropdownfield): prevent language switching and log error --- inc/field/dropdownfield.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/inc/field/dropdownfield.class.php b/inc/field/dropdownfield.class.php index 8de0c67b3..17193ffb4 100644 --- a/inc/field/dropdownfield.class.php +++ b/inc/field/dropdownfield.class.php @@ -700,10 +700,6 @@ public function parseObjectProperties( // $questionID = $question->fields['id']; $questionID = $this->getQuestion()->getID(); - // We need english locale to search searchOptions by name - $oldLocale = $TRANSLATE->getLocale(); - $TRANSLATE->setLocale("en_GB"); - // Load target item from DB $itemtype = $this->question->fields['itemtype']; @@ -712,6 +708,10 @@ public function parseObjectProperties( return $content; } + // We need english locale to search searchOptions by name + $oldLocale = $TRANSLATE->getLocale(); + $TRANSLATE->setLocale("en_GB"); + $item = new $itemtype; $item->getFromDB($answer); @@ -726,6 +726,11 @@ public function parseObjectProperties( // Convert Property_Name to Property Name $property = str_replace("_", " ", $property); $searchOption = $item->getSearchOptionByField("name", $property); + if (count($searchOption) == 0) { + trigger_error("No search option found for $property", E_USER_WARNING); + $TRANSLATE->setLocale($oldLocale); + return $content; + } // Execute search $data = Search::prepareDatasForSearch(get_class($item), [