@@ -151,6 +151,19 @@ abstract public function subquestion(question_attempt $qa,
151151 question_display_options $ options , $ index ,
152152 question_graded_automatically $ subq );
153153
154+ /**
155+ * Format question text and process embedded files using the parent question context.
156+ *
157+ * @param question_attempt $qa the current attempt.
158+ * @param string $text the text to format.
159+ * @param int $format the text format.
160+ * @return string formatted text.
161+ */
162+ protected function format_embedded_text (question_attempt $ qa , string $ text , int $ format ): string {
163+ $ question = $ qa ->get_question ();
164+ return $ question ->format_text ($ text , $ format , $ qa , 'question ' , 'questiontext ' , $ question ->id );
165+ }
166+
154167 /**
155168 * Render the feedback pop-up contents.
156169 *
@@ -327,15 +340,21 @@ public function subquestion(question_attempt $qa, question_display_options $opti
327340 $ correctanswer = $ subq ->get_correct_answer ();
328341 }
329342
330- $ feedbackpopup = $ this ->feedback_popup ($ subq , $ matchinganswer ->fraction ,
331- $ subq ->format_text ($ matchinganswer ->feedback , $ matchinganswer ->feedbackformat ,
332- $ qa , 'question ' , 'answerfeedback ' , $ matchinganswer ->id ),
333- s ($ correctanswer ->answer ), $ options );
343+ $ feedbackpopup = $ this ->feedback_popup (
344+ $ subq ,
345+ $ matchinganswer ->fraction ,
346+ $ this ->format_embedded_text ($ qa , $ matchinganswer ->feedback , $ matchinganswer ->feedbackformat ),
347+ s ($ correctanswer ->answer ),
348+ $ options
349+ );
334350
335351 $ output = html_writer::start_tag ('span ' , ['class ' => 'subquestion ' ]);
336352
337- $ output .= html_writer::tag ('label ' , $ this ->get_answer_label (),
338- array ('class ' => 'subq accesshide ' , 'for ' => $ inputattributes ['id ' ]));
353+ $ output .= html_writer::tag (
354+ 'label ' ,
355+ $ this ->get_answer_label (),
356+ ['class ' => 'subq accesshide ' , 'for ' => $ inputattributes ['id ' ]]
357+ );
339358 $ output .= html_writer::empty_tag ('input ' , $ inputattributes );
340359 $ output .= $ this ->get_feedback_image ($ feedbackimg , $ feedbackpopup );
341360 $ output .= html_writer::end_tag ('span ' );
@@ -368,8 +387,7 @@ public function subquestion(question_attempt $qa, question_display_options $opti
368387 $ rightanswer = null ;
369388 foreach ($ subq ->get_order ($ qa ) as $ value => $ ansid ) {
370389 $ ans = $ subq ->answers [$ ansid ];
371- $ choices [$ value ] = $ subq ->format_text ($ ans ->answer , $ ans ->answerformat ,
372- $ qa , 'question ' , 'answer ' , $ ansid );
390+ $ choices [$ value ] = $ this ->format_embedded_text ($ qa , $ ans ->answer , $ ans ->answerformat );
373391 if ($ subq ->is_choice_selected ($ response , $ value )) {
374392 $ matchinganswer = $ ans ;
375393 }
@@ -397,15 +415,20 @@ public function subquestion(question_attempt $qa, question_display_options $opti
397415 if (!$ matchinganswer ) {
398416 $ matchinganswer = new question_answer (0 , '' , null , '' , FORMAT_HTML );
399417 }
400- $ feedbackpopup = $ this ->feedback_popup ($ subq , $ matchinganswer ->fraction ,
401- $ subq ->format_text ($ matchinganswer ->feedback , $ matchinganswer ->feedbackformat ,
402- $ qa , 'question ' , 'answerfeedback ' , $ matchinganswer ->id ),
403- $ subq ->format_text ($ rightanswer ->answer , $ rightanswer ->answerformat ,
404- $ qa , 'question ' , 'answer ' , $ rightanswer ->id ), $ options );
418+ $ feedbackpopup = $ this ->feedback_popup (
419+ $ subq ,
420+ $ matchinganswer ->fraction ,
421+ $ this ->format_embedded_text ($ qa , $ matchinganswer ->feedback , $ matchinganswer ->feedbackformat ),
422+ $ this ->format_embedded_text ($ qa , $ rightanswer ->answer , $ rightanswer ->answerformat ),
423+ $ options
424+ );
405425
406426 $ output = html_writer::start_tag ('span ' , array ('class ' => 'subquestion ' ));
407- $ output .= html_writer::tag ('label ' , $ this ->get_answer_label (),
408- array ('class ' => 'subq accesshide ' , 'for ' => $ inputattributes ['id ' ]));
427+ $ output .= html_writer::tag (
428+ 'label ' ,
429+ $ this ->get_answer_label (),
430+ ['class ' => 'subq accesshide ' , 'for ' => $ inputattributes ['id ' ]]
431+ );
409432 $ output .= $ select ;
410433 $ output .= $ this ->get_feedback_image ($ feedbackimg , $ feedbackpopup );
411434 $ output .= html_writer::end_tag ('span ' );
@@ -468,16 +491,19 @@ public function subquestion(question_attempt $qa, question_display_options $opti
468491
469492 $ result .= $ this ->choice_wrapper_start ($ class );
470493 $ result .= html_writer::empty_tag ('input ' , $ inputattributes );
471- $ result .= html_writer::tag ('label ' , $ subq ->format_text ($ ans ->answer ,
472- $ ans ->answerformat , $ qa , 'question ' , 'answer ' , $ ansid ),
473- array ('for ' => $ inputattributes ['id ' ], 'class ' => 'form-check-label text-body ' ));
494+ $ result .= html_writer::tag (
495+ 'label ' ,
496+ $ this ->format_embedded_text ($ qa , $ ans ->answer , $ ans ->answerformat ),
497+ ['for ' => $ inputattributes ['id ' ], 'class ' => 'form-check-label text-body ' ]
498+ );
474499 $ result .= $ feedbackimg ;
475500
476501 if ($ options ->feedback && $ isselected && trim ($ ans ->feedback )) {
477- $ result .= html_writer::tag ('div ' ,
478- $ subq ->format_text ($ ans ->feedback , $ ans ->feedbackformat ,
479- $ qa , 'question ' , 'answerfeedback ' , $ ansid ),
480- array ('class ' => 'specificfeedback ' ));
502+ $ result .= html_writer::tag (
503+ 'div ' ,
504+ $ this ->format_embedded_text ($ qa , $ ans ->feedback , $ ans ->feedbackformat ),
505+ ['class ' => 'specificfeedback ' ]
506+ );
481507 }
482508
483509 $ result .= $ this ->choice_wrapper_end ();
@@ -499,9 +525,11 @@ public function subquestion(question_attempt $qa, question_display_options $opti
499525 foreach ($ subq ->answers as $ ans ) {
500526 if (question_state::graded_state_for_fraction ($ ans ->fraction ) ==
501527 question_state::$ gradedright ) {
502- $ feedback [] = get_string ('correctansweris ' , 'qtype_multichoice ' ,
503- $ subq ->format_text ($ ans ->answer , $ ans ->answerformat ,
504- $ qa , 'question ' , 'answer ' , $ ansid ));
528+ $ feedback [] = get_string (
529+ 'correctansweris ' ,
530+ 'qtype_multichoice ' ,
531+ $ this ->format_embedded_text ($ qa , $ ans ->answer , $ ans ->answerformat )
532+ );
505533 break ;
506534 }
507535 }
@@ -661,16 +689,19 @@ public function subquestion(question_attempt $qa, question_display_options $opti
661689
662690 $ result .= $ this ->choice_wrapper_start ($ class );
663691 $ result .= html_writer::empty_tag ('input ' , $ inputattributes );
664- $ result .= html_writer::tag ('label ' , $ subq ->format_text ($ ans ->answer ,
665- $ ans ->answerformat , $ qa , 'question ' , 'answer ' , $ ansid ),
666- ['for ' => $ inputattributes ['id ' ], 'class ' => 'form-check-label text-body ' ]);
692+ $ result .= html_writer::tag (
693+ 'label ' ,
694+ $ this ->format_embedded_text ($ qa , $ ans ->answer , $ ans ->answerformat ),
695+ ['for ' => $ inputattributes ['id ' ], 'class ' => 'form-check-label text-body ' ]
696+ );
667697 $ result .= $ feedbackimg ;
668698
669699 if ($ options ->feedback && $ isselected && trim ($ ans ->feedback )) {
670- $ result .= html_writer::tag ('div ' ,
671- $ subq ->format_text ($ ans ->feedback , $ ans ->feedbackformat ,
672- $ qa , 'question ' , 'answerfeedback ' , $ ansid ),
673- array ('class ' => 'specificfeedback ' ));
700+ $ result .= html_writer::tag (
701+ 'div ' ,
702+ $ this ->format_embedded_text ($ qa , $ ans ->feedback , $ ans ->feedbackformat ),
703+ ['class ' => 'specificfeedback ' ]
704+ );
674705 }
675706
676707 $ result .= $ this ->choice_wrapper_end ();
@@ -692,7 +723,7 @@ public function subquestion(question_attempt $qa, question_display_options $opti
692723 $ correct = [];
693724 foreach ($ subq ->answers as $ ans ) {
694725 if (question_state::graded_state_for_fraction ($ ans ->fraction ) != question_state::$ gradedwrong ) {
695- $ correct [] = $ subq -> format_text ( $ ans -> answer , $ ans ->answerformat , $ qa , ' question ' , ' answer ' , $ ans ->id );
726+ $ correct [] = $ this -> format_embedded_text ( $ qa , $ ans ->answer , $ ans ->answerformat );
696727 }
697728 }
698729 $ correct = '<ul><li> ' .implode ('</li><li> ' , $ correct ).'</li></ul> ' ;
0 commit comments