Skip to content

Commit 7781f1e

Browse files
committed
broken-save - Show not saved warning for most Moodle errors. Fix display of Moodle errors.
1 parent 3b593d9 commit 7781f1e

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

edit_stack_form.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,21 @@ public function validation($fromform, $files) {
973973
if (empty($fromform['isbroken'])) {
974974
return $allerrors;
975975
} else {
976-
if (array_search(stack_string('youmustconfirm'), $allerrors)) {
976+
$mustconfirm = (array_search(stack_string('youmustconfirm'), $allerrors) === false) ? false : true;
977+
if ($errors || $mustconfirm) {
978+
$errortext = stack_string('notsaved');
979+
if ($errors) {
980+
$errortext .= ' ' . stack_string('moodleerrors');
981+
}
982+
if ($mustconfirm) {
983+
$errortext .= ' ' . stack_string('mustconfirm');
984+
}
985+
977986
$allerrors['versioninfo'] = isset($allerrors['versioninfo']) ?
978-
stack_string('notsaved') . ' ' . $allerrors['versioninfo'] : stack_string('notsaved');
987+
$errortext . ' ' . $allerrors['versioninfo'] : $errortext;
979988
return $allerrors;
980989
} else {
990+
// This is going to be [].
981991
return $errors;
982992
}
983993
}

lang/en/qtype_stack.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@
142142
$string['fixdollars_help'] = 'This option is useful if are copying and pasting (or typing) TeX with <code>$...$</code> and <code>$$...$$</code> delimiters. Those delimiters will be replaced by the recommended delimiters during the save process.';
143143
$string['forbiddendoubledollars'] = 'Please use the delimiters <code>\(...\)</code> for inline maths and <code>\[...\]</code> for display maths. <code>$...$</code> and <code>$$...$$</code> are not permitted. There is an option at the end of the form to fix this automatically.';
144144
$string['isbroken'] = 'Save as broken';
145-
$string['isbrokenlabel'] = 'Mark the question as broken. This will allow the question to be saved even with errors but it will not be displayed to students.';
146-
$string['isbroken_help'] = 'This option allows you to save your work even if a question is incomplete or has errors. You or a colleague can then return to work on it later. You will still need to tick the boxes to confirm any deletion of inputs or PRTs before the question will save.';
145+
$string['isbrokenlabel'] = 'Mark the question as broken. This will allow the question to be saved even with most errors but it will not be displayed to students.';
146+
$string['isbroken_help'] = 'This option allows you to save your work even if a question is incomplete or has errors. You or a colleague can then return to work on it later. You will still need to supply required fields and tick the boxes to confirm any deletion of inputs or PRTs before the question will save.';
147147
$string['forbidfloat'] = 'Forbid float';
148148
$string['forbidfloat_help'] = 'If set to yes, then any answer of the student which has a floating point number will be rejected as invalid.';
149149
$string['forbidfloat_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Inputs.md#Forbid_Floats';
@@ -404,7 +404,9 @@
404404
$string['variantsselectionseed_help'] = 'Normally you can leave this box blank. If, however, you want two different questions in a quiz to use the same random seed, then type the same string in this box for the two questions (and deploy the same set of random seeds, if you are using deployed variants) and the random seeds for the two questions will be synchronised.';
405405
$string['verifyquestionandupdate'] = 'Verify the question text and update the form';
406406
$string['youmustconfirm'] = 'You must confirm here.';
407-
$string['notsaved'] = '** QUESTION WAS NOT SAVED ** You have changes to confirm.';
407+
$string['notsaved'] = '** QUESTION WAS NOT SAVED **';
408+
$string['mustconfirm'] = 'You have changes to confirm.';
409+
$string['moodleerrors'] = 'You have errors related to Moodle\'s basic question setup.';
408410

409411
// Strings used by input elements.
410412
$string['studentinputtoolong'] = 'Your input is longer than permitted by STACK.';

questiontype.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,9 @@ public function validate_fromform($fromform, $errors, $question) {
18981898
$messages[$key] = implode(' ', $val);
18991899
}
19001900
}
1901-
$errors[$field] = implode(' ', $messages);
1901+
// Fixed to handle strings. We got away with e.g. default mark errors
1902+
// just not showing before but this previously threw an exception in PHP 8.x.
1903+
$errors[$field] = (is_array($messages)) ? implode(' ', $messages) : $messages;
19021904
$errorsexit = true;
19031905
} else {
19041906
unset($errors[$field]);

0 commit comments

Comments
 (0)