Merge branch 'MDL-69788-310' of https://github.com/paulholden/moodle into MOODLE_310_STABLE

This commit is contained in:
Adrian Greeve
2020-10-22 09:07:54 +08:00
5 changed files with 85 additions and 2 deletions
+30
View File
@@ -4933,6 +4933,36 @@ class admin_setting_langlist extends admin_setting_configtext {
parent::__construct('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS);
}
/**
* Validate that each language identifier exists on the site
*
* @param string $data
* @return bool|string True if validation successful, otherwise error string
*/
public function validate($data) {
$parentcheck = parent::validate($data);
if ($parentcheck !== true) {
return $parentcheck;
}
if ($data === '') {
return true;
}
// Normalize language identifiers.
$langcodes = array_map('trim', explode(',', $data));
foreach ($langcodes as $langcode) {
// If the langcode contains optional alias, split it out.
[$langcode, ] = preg_split('/\s*\|\s*/', $langcode, 2);
if (!get_string_manager()->translation_exists($langcode)) {
return get_string('invalidlanguagecode', 'error', $langcode);
}
}
return true;
}
/**
* Save the new setting
*