MDL-61876 question: apply format_text to input only
This commit is contained in:
@@ -57,7 +57,8 @@ class qtype_gapselect_renderer extends qtype_elements_embedded_in_question_text_
|
||||
$orderedchoices = $question->get_ordered_choices($group);
|
||||
$selectoptions = array();
|
||||
foreach ($orderedchoices as $orderedchoicevalue => $orderedchoice) {
|
||||
$selectoptions[$orderedchoicevalue] = $orderedchoice->text;
|
||||
$selectoptions[$orderedchoicevalue] = $question->format_text($orderedchoice->text,
|
||||
$question->questiontextformat, $qa, 'question', 'questiontext', $question->id);
|
||||
}
|
||||
|
||||
$feedbackimage = '';
|
||||
|
||||
@@ -40,16 +40,26 @@ abstract class qtype_elements_embedded_in_question_text_renderer
|
||||
$question = $qa->get_question();
|
||||
|
||||
$questiontext = '';
|
||||
// Glue question fragments together using unique placeholders, apply format_text to the result
|
||||
// and then substitute each placeholder with the embedded element.
|
||||
// This will ensure that format_text() is applied to the whole question but not to the embedded elements.
|
||||
$placeholders = $this->get_fragments_glue_placeholders($question->textfragments);
|
||||
foreach ($question->textfragments as $i => $fragment) {
|
||||
if ($i > 0) {
|
||||
$questiontext .= $this->embedded_element($qa, $i, $options);
|
||||
$questiontext .= $placeholders[$i];
|
||||
$embeddedelements[$placeholders[$i]] = $this->embedded_element($qa, $i, $options);
|
||||
}
|
||||
$questiontext .= $fragment;
|
||||
}
|
||||
$questiontext = $question->format_text($questiontext,
|
||||
$question->questiontextformat, $qa, 'question', 'questiontext', $question->id);
|
||||
foreach ($placeholders as $i => $placeholder) {
|
||||
$questiontext = preg_replace('/'. preg_quote($placeholder, '/') . '/',
|
||||
$embeddedelements[$placeholder], $questiontext);
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$result .= html_writer::tag('div', $question->format_text($questiontext,
|
||||
$question->questiontextformat, $qa, 'question', 'questiontext', $question->id),
|
||||
$result .= html_writer::tag('div', $questiontext,
|
||||
array('class' => $this->qtext_classname(), 'id' => $this->qtext_id($qa)));
|
||||
|
||||
$result .= $this->post_qtext_elements($qa, $options);
|
||||
@@ -63,6 +73,32 @@ abstract class qtype_elements_embedded_in_question_text_renderer
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find strings that we can use to glue the fragments with
|
||||
*
|
||||
* These strings have to be all different and neither of them can be present in the text
|
||||
*
|
||||
* @param array $fragments
|
||||
* @return array array with indexes from 1 to count($fragments)-1
|
||||
*/
|
||||
protected function get_fragments_glue_placeholders($fragments) {
|
||||
$fragmentscount = count($fragments);
|
||||
if ($fragmentscount <= 1) {
|
||||
return [];
|
||||
}
|
||||
$prefix = '[[$';
|
||||
$postfix = ']]';
|
||||
$text = join('', $fragments);
|
||||
while (preg_match('/' . preg_quote($prefix, '/') . '\\d+' . preg_quote($postfix, '/') . '/', $text)) {
|
||||
$prefix .= '$';
|
||||
}
|
||||
$glues = [];
|
||||
for ($i = 1; $i < $fragmentscount; $i++) {
|
||||
$glues[$i] = $prefix . $i . $postfix;
|
||||
}
|
||||
return $glues;
|
||||
}
|
||||
|
||||
protected function qtext_classname() {
|
||||
return 'qtext';
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ This files describes API changes for question type plugins.
|
||||
question_manually_gradable.
|
||||
+ The default implementation of is_gradable_response has been moved from question_graded_automatically to
|
||||
question_with_responses.
|
||||
+ Note that format_text() is no longer applied to the results of
|
||||
qtype_elements_embedded_in_question_text_renderer::embedded_element(). If question type overrides
|
||||
this method make sure you apply format_text() to any text that came from a user.
|
||||
|
||||
=== 3.1.5, 3.2.2, 3.3 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user