MDL-74608 activities: a new option to force the activity language

For a long time, Moodle has had the feature to force the language
for a whole course. This change adds the same feature at activity
level.

The course-level feature was controlled by a capability
moodle/course:setforcedlanguage, and I decided to use the same
capability to control this feature. I think a new capability would be
overkill.
This commit is contained in:
Tim Hunt
2022-08-15 22:15:52 +01:00
parent 896e126a66
commit 8babdbd396
44 changed files with 528 additions and 85 deletions
+13 -2
View File
@@ -70,6 +70,11 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
if (isset($moduleinfo->downloadcontent)) {
$newcm->downloadcontent = $moduleinfo->downloadcontent;
}
if (has_capability('moodle/course:setforcedlanguage', context_course::instance($course->id))) {
$newcm->lang = $moduleinfo->lang ?? null;
} else {
$newcm->lang = null;
}
$newcm->groupmode = $moduleinfo->groupmode;
$newcm->groupingid = $moduleinfo->groupingid;
$completion = new completion_info($course);
@@ -552,6 +557,13 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
$moduleinfo->course = $course->id;
$moduleinfo = set_moduleinfo_defaults($moduleinfo);
$modcontext = context_module::instance($moduleinfo->coursemodule);
if (has_capability('moodle/course:setforcedlanguage', $modcontext)) {
$cm->lang = $moduleinfo->lang ?? null;
} else {
unset($cm->lang);
}
if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) {
$moduleinfo->groupmode = $cm->groupmode; // Keep original.
}
@@ -611,8 +623,6 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
$DB->update_record('course_modules', $cm);
$modcontext = context_module::instance($moduleinfo->coursemodule);
// Update embedded links and save files.
if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true)) {
$moduleinfo->intro = file_save_draft_area_files($moduleinfo->introeditor['itemid'], $modcontext->id,
@@ -745,6 +755,7 @@ function get_moduleinfo_data($cm, $course) {
$data->completiongradeitemnumber = $cm->completiongradeitemnumber;
$data->showdescription = $cm->showdescription;
$data->downloadcontent = $cm->downloadcontent;
$data->lang = $cm->lang;
$data->tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $cm->id);
if (!empty($CFG->enableavailability)) {
$data->availabilityconditionsjson = $cm->availability;