weekly release 3.3.7+
[moodle.git] / user / language_form.php
blob4dab6bed2fa33ca985d1e29395106b10fbcf89c7
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Form to edit a users preferred language
20 * @copyright 1999 Martin Dougiamas http://dougiamas.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 * @package core_user
25 if (!defined('MOODLE_INTERNAL')) {
26 die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
29 require_once($CFG->dirroot.'/lib/formslib.php');
31 /**
32 * Class user_edit_form.
34 * @copyright 1999 Martin Dougiamas http://dougiamas.com
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class user_edit_language_form extends moodleform {
39 /**
40 * Define the form.
42 public function definition () {
43 global $CFG, $COURSE, $USER;
45 $mform = $this->_form;
46 $userid = $USER->id;
48 if (is_array($this->_customdata)) {
49 if (array_key_exists('userid', $this->_customdata)) {
50 $userid = $this->_customdata['userid'];
54 // Add some extra hidden fields.
55 $mform->addElement('hidden', 'id');
56 $mform->setType('id', PARAM_INT);
57 $mform->addElement('hidden', 'course', $COURSE->id);
58 $mform->setType('course', PARAM_INT);
60 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
61 $mform->setDefault('lang', core_user::get_property_default('lang'));
63 $this->add_action_buttons(true, get_string('savechanges'));
66 /**
67 * Extend the form definition after the data has been parsed.
69 public function definition_after_data() {
70 global $CFG, $DB, $OUTPUT;
72 $mform = $this->_form;
74 // If language does not exist, use site default lang.
75 if ($langsel = $mform->getElementValue('lang')) {
76 $lang = reset($langsel);
77 // Check lang exists.
78 if (!get_string_manager()->translation_exists($lang, false)) {
79 $langel =& $mform->getElement('lang');
80 $langel->setValue(core_user::get_property_default('lang'));