Skip to content

Commit

Permalink
fix(dropdownfield): prevent language switching and log error
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jun 13, 2023
1 parent a9e6cbc commit 49f8fc0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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);

Expand All @@ -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), [
Expand Down

0 comments on commit 49f8fc0

Please sign in to comment.