Draft: fix for xml export of items with html - #86
Conversation
fixes ndunand#65 as question items with html are escaped
danowar2k
left a comment
There was a problem hiding this comment.
This is an internal review before removing draft status, a-kempka and myself are colleagues.
There are changes to be done or to be discussed....
| * @param mixed $value | ||
| * @return string | ||
| */ | ||
| protected static function text_from_editor($value): string { |
There was a problem hiding this comment.
This assumes another change (having an editor form field for row shorttext) to already have happened. As this isn't the case, this should not be in this PR.
| * @param object $question | ||
| * @return void | ||
| */ | ||
| protected static function normalise_rows_shorttext($question): void { |
There was a problem hiding this comment.
See above, this isn't necessary as long as there is no editor form field for row shorttext.
| global $DB; | ||
| $store = new question_matrix_store(); | ||
|
|
||
| // Ensure rows_shorttext are plain strings (if coming from an HTML editor). |
There was a problem hiding this comment.
Part three, this is not part of the solution for this issue.
| 'id' => $rowid, | ||
| 'matrixid' => $matrixid, | ||
| 'shorttext' => $question->rows_shorttext[$i], | ||
| 'shorttext' => $question->rows_shorttext[$i], // already normalised to string |
There was a problem hiding this comment.
This comment only makes sense if the above changes are in this PR, which they shouldn't be.
| $question->rows_shorttext[$index] = $format->getpath($rowxml, ['#', 'shorttext', 0, '#'], ''); | ||
| // Support both legacy: <shorttext>text</shorttext> | ||
| // and new: <shorttext format="..."><text>html</text></shorttext> | ||
| $shorttexthtml = $format->getpath($rowxml, ['#', 'shorttext', 0, '#', 'text', 0, '#'], null); |
There was a problem hiding this comment.
There exists a function called import_text() that does some small post-processing. You should probably use that, so:
$shorttexthtml = $format->getpath($rowxml, ['#', 'shorttext', 0, '#', 'text'], null);
if ($shorttexthtml !== null) {
// Postprocess text node
$shorttexthtml = import_text($shorttexthtml);
} else {
// An older exported matrix question
$shorttexthtml = $format->getpath($rowxml, ['#', 'shorttext', 0, '#'], '');
}
| // Legacy path (no <text> child). | ||
| $shorttexthtml = $format->getpath($rowxml, ['#', 'shorttext', 0, '#'], ''); | ||
| } | ||
| $question->rows_shorttext[$index] = (string)$shorttexthtml; |
There was a problem hiding this comment.
I don't think you need the additional casting to string.
fixes #65 as question items with html are escaped