@@ -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 [].
0 commit comments