Skip to content

Commit

Permalink
MDL-67532 badges: better default for new badge language.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Feb 7, 2020
1 parent 4e90332 commit 5253834
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions badges/classes/form/badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function definition() {
$mform = $this->_form;
$badge = (isset($this->_customdata['badge'])) ? $this->_customdata['badge'] : false;
$action = $this->_customdata['action'];
$languages = get_string_manager()->get_list_of_languages();

$mform->addElement('header', 'badgedetails', get_string('badgedetails', 'badges'));
$mform->addElement('text', 'name', get_string('name'), array('size' => '70'));
Expand All @@ -61,6 +60,8 @@ public function definition() {
$mform->addElement('text', 'version', get_string('version', 'badges'), array('size' => '70'));
$mform->setType('version', PARAM_TEXT);
$mform->addHelpButton('version', 'version', 'badges');

$languages = get_string_manager()->get_list_of_languages();
$mform->addElement('select', 'language', get_string('language'), $languages);
$mform->addHelpButton('language', 'language', 'badges');

Expand Down Expand Up @@ -157,7 +158,16 @@ public function definition() {
$mform->setType('action', PARAM_TEXT);

if ($action == 'new') {
$mform->setDefault('language', $CFG->lang);
// Try to set default badge language to that of current language, or it's parent.
$language = current_language();
if (isset($languages[$language])) {
$defaultlanguage = $language;
} else {
// Calling get_parent_language returns an empty string instead of 'en'.
$defaultlanguage = get_parent_language($language) ?: 'en';
}

$mform->setDefault('language', $defaultlanguage);
$this->add_action_buttons(true, get_string('createbutton', 'badges'));
} else {
// Add hidden fields.
Expand Down

0 comments on commit 5253834

Please sign in to comment.