@@ -83,10 +83,16 @@ public function formulation_and_controls(question_attempt $qa, question_display_
83
83
}
84
84
85
85
try {
86
+ /** @var array<string, int>|null $uploaddraftareas */
87
+ $ uploaddraftareas = null ;
88
+
86
89
$ questiondivid = $ qa ->get_outer_question_div_unique_id ();
87
90
$ qpyresponseid = $ questiondivid . '-qpy-response ' ;
88
- $ formulationcb = function (qtype_questionpy_renderer $ renderer ) use ($ qa , $ question , $ options , $ qpyresponseid ) {
89
- return $ renderer ->formulation_controls_feedback_in_iframe ($ qa , $ question ->ui , $ options , $ qpyresponseid );
91
+ $ formulationcb = function (qtype_questionpy_renderer $ renderer ) use ($ qa , $ question , $ options , $ qpyresponseid , &$ uploaddraftareas ) {
92
+ $ quirenderer = question_ui_renderer::render ($ question ->ui ->formulation , $ question ->ui ->placeholders , $ options , $ qa );
93
+ $ uploaddraftareas = $ quirenderer ->draftareas ;
94
+
95
+ return $ renderer ->formulation_controls_feedback_in_iframe ($ qa , $ question ->ui , $ quirenderer , $ options , $ qpyresponseid );
90
96
};
91
97
$ iframesrc = $ this ->get_iframe_document ($ options ->context , $ question , $ formulationcb );
92
98
@@ -125,6 +131,17 @@ public function formulation_and_controls(question_attempt $qa, question_display_
125
131
<iframe id=" {$ iframeid }" srcdoc=" {$ iframesrc }"></iframe>
126
132
EOA ;
127
133
134
+ if ($ uploaddraftareas === null ) {
135
+ throw new coding_exception ('$uploaddraftareas was not set ' );
136
+ }
137
+ if (count ($ uploaddraftareas ) > 0 ) {
138
+ $ result .= html_writer::empty_tag ('input ' , [
139
+ 'type ' => 'hidden ' ,
140
+ 'name ' => $ qa ->get_field_prefix () . constants::QT_VAR_DRAFT_AREAS ,
141
+ 'value ' => json_encode ($ uploaddraftareas , JSON_FORCE_OBJECT ),
142
+ ]);
143
+ }
144
+
128
145
return $ result ;
129
146
} catch (Throwable $ t ) {
130
147
global $ USER ;
@@ -220,13 +237,11 @@ protected function get_iframe_document(context $context, qtype_questionpy_questi
220
237
* @throws moodle_exception
221
238
*/
222
239
protected function formulation_controls_feedback_in_iframe (
223
- question_attempt $ qa , attempt_ui $ ui ,
240
+ question_attempt $ qa , attempt_ui $ ui , question_ui_renderer $ renderer ,
224
241
question_display_options $ options , string $ qpyresponseid
225
242
): string {
226
243
global $ CFG ;
227
244
228
- $ renderer = question_ui_renderer::render ($ ui ->formulation , $ ui ->placeholders , $ options , $ qa );
229
-
230
245
$ warningshtml = '' ;
231
246
if ($ renderer ->warnings ) {
232
247
global $ USER ;
0 commit comments