Skip to content

Commit 1dc56e9

Browse files
committed
broken-save - Update not-saved warning
1 parent 595201a commit 1dc56e9

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

edit_stack_form.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -995,24 +995,34 @@ public function validation($fromform, $files) {
995995
$errors = parent::validation($fromform, $files);
996996
$qtype = new qtype_stack();
997997
$allerrors = $qtype->validate_fromform($fromform, $errors, $this->question);
998+
$mustconfirm = (array_search(stack_string('youmustconfirm'), $allerrors) === false) ? false : true;
999+
// Add not saved warning but only when attempting to save, not on loading question.
1000+
// Moodle errors and confirmation issues will always be on save as question cannot be saved and thus
1001+
// cannot be loaded in this state even if marked as broken. If there are STACK issues, we only flag
1002+
// if question is not marked as broken and it's a submit.
1003+
if ($errors || $mustconfirm ||
1004+
($allerrors && empty($fromform['isbroken']) && !empty(optional_param_array('questiontext', [], PARAM_RAW)))) {
1005+
$errortext = stack_string('notsaved') . '<br>';
1006+
if ($errors) {
1007+
$errortext .= stack_string_error('moodleerrors') . '<br>';
1008+
}
1009+
if ($mustconfirm) {
1010+
$errortext .= stack_string_error('mustconfirm') . '<br>';
1011+
}
1012+
if (empty($fromform['isbroken']) && $allerrors != $errors) {
1013+
$errortext .= stack_string_error('stackerrors') . '<br>';
1014+
}
1015+
1016+
$allerrors['versioninfo'] = isset($allerrors['versioninfo']) ?
1017+
$errortext . ' ' . $allerrors['versioninfo'] : $errortext;
1018+
}
9981019
// Ignore STACK-specific validation if question is marked as broken unless
9991020
// a confirmation is required.
10001021
// Moodle validation errors always returned.
10011022
if (empty($fromform['isbroken'])) {
10021023
return $allerrors;
10031024
} else {
1004-
$mustconfirm = (array_search(stack_string('youmustconfirm'), $allerrors) === false) ? false : true;
10051025
if ($errors || $mustconfirm) {
1006-
$errortext = stack_string('notsaved');
1007-
if ($errors) {
1008-
$errortext .= ' ' . stack_string('moodleerrors');
1009-
}
1010-
if ($mustconfirm) {
1011-
$errortext .= ' ' . stack_string('mustconfirm');
1012-
}
1013-
1014-
$allerrors['versioninfo'] = isset($allerrors['versioninfo']) ?
1015-
$errortext . ' ' . $allerrors['versioninfo'] : $errortext;
10161026
return $allerrors;
10171027
} else {
10181028
// This is going to be [].

lang/en/qtype_stack.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@
407407
$string['notsaved'] = '** QUESTION WAS NOT SAVED **';
408408
$string['mustconfirm'] = 'You have changes to confirm.';
409409
$string['moodleerrors'] = 'You have errors related to Moodle\'s basic question setup.';
410+
$string['stackerrors'] = 'You have errors in your question.';
410411

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

0 commit comments

Comments
 (0)