Skip to content

Commit

Permalink
Add multilang support for select field
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed May 20, 2024
1 parent 0dba972 commit 0a891ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions field/field_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ protected function add_option_dialog() {
get_string('renameoption', 'datalynx') . '</th><th>' .
get_string('deleteoption', 'datalynx') . '</th></thead><tbody>');
foreach ($options as $id => $option) {
$option = htmlspecialchars($option);
$group[] = &$mform->createElement('static', null, null,
"<tr><td>{$option}</td><td>");
$group[] = &$mform->createElement('text', "renameoption[{$id}]", '', array('size' => 32));
Expand Down
9 changes: 4 additions & 5 deletions field/select/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function render_edit_mode(MoodleQuickForm &$mform, stdClass $entry, array
foreach ($menuoptions as $id => $name) {
$option = new stdClass();
$option->id = $id;
$option->name = $name;
$option->name = format_string($name);
$menuoptions[$id] = $option;
}
// Sort the options alphabetically.
Expand Down Expand Up @@ -122,22 +122,21 @@ public function render_display_mode(stdClass $entry, array $options): string {
$str[] = "$isselected $option";
}
$str = implode(',', $str);
return $str;
return format_string($str);
}

if (!empty($options['key'])) {
if ($selected) {
return $selected;
return format_string($selected);
} else {
return '';
}
}

if ($selected && $selected <= count($options)) {
return $options[$selected];
return format_string($options[$selected]);
}
}

return '';
}

Expand Down

0 comments on commit 0a891ee

Please sign in to comment.