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
+6 -1
View File
@@ -268,8 +268,13 @@ abstract class testing_module_generator extends component_generator_base {
debugging('Did you forget to enable completion tracking for the course before generating module with completion tracking?', DEBUG_DEVELOPER);
}
if (!empty($record->lang) && !has_capability('moodle/course:setforcedlanguage', context_course::instance($course->id))) {
throw new coding_exception('Attempt to generate an activity when the current user does not have ' .
'permission moodle/course:setforcedlanguage. This does not work.');
}
// Add the module to the course.
$moduleinfo = add_moduleinfo($record, $course, $mform = null);
$moduleinfo = add_moduleinfo($record, $course);
// Prepare object to return with additional field cmid.
$instance = $DB->get_record($this->get_modulename(), array('id' => $moduleinfo->instance), '*', MUST_EXIST);