MDL-75075 quiz: Show question tags as non-links to avoid errors
This commit is contained in:
@@ -45,7 +45,8 @@ class question_name_text_column extends question_name_column {
|
||||
if ($labelfor) {
|
||||
echo \html_writer::start_tag('label', ['for' => $labelfor]);
|
||||
}
|
||||
echo quiz_question_tostring($question, false, true, true, $question->tags);
|
||||
echo quiz_question_tostring($question, false, true, true,
|
||||
$question->tags, false);
|
||||
if ($labelfor) {
|
||||
echo \html_writer::end_tag('label');
|
||||
}
|
||||
|
||||
@@ -1637,10 +1637,11 @@ function quiz_get_js_module() {
|
||||
* @param bool $showidnumber If true, show the question's idnumber, if any. False by default.
|
||||
* @param core_tag_tag[]|bool $showtags if array passed, show those tags. Else, if true, get and show tags,
|
||||
* else, don't show tags (which is the default).
|
||||
* @param bool $displaytaglink Indicates whether the tag should be displayed as a link.
|
||||
* @return string HTML fragment.
|
||||
*/
|
||||
function quiz_question_tostring($question, $showicon = false, $showquestiontext = true,
|
||||
$showidnumber = false, $showtags = false) {
|
||||
$showidnumber = false, $showtags = false, $displaytaglink = true) {
|
||||
global $OUTPUT;
|
||||
$result = '';
|
||||
|
||||
@@ -1667,7 +1668,7 @@ function quiz_question_tostring($question, $showicon = false, $showquestiontext
|
||||
$tags = [];
|
||||
}
|
||||
if ($tags) {
|
||||
$result .= $OUTPUT->tag_list($tags, null, 'd-inline', 0, null, true);
|
||||
$result .= $OUTPUT->tag_list($tags, null, 'd-inline', 0, null, true, $displaytaglink);
|
||||
}
|
||||
|
||||
// Question text.
|
||||
|
||||
@@ -121,6 +121,32 @@ class locallib_test extends \advanced_testcase {
|
||||
'<span class="questiontext">What sort of INEQUALITY is x < y[?]' . "\n" . '</span>', $summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the method quiz_question_to_string with the tag display.
|
||||
*
|
||||
* @covers ::quiz_question_tostring
|
||||
*/
|
||||
public function test_quiz_question_tostring_with_tags(): void {
|
||||
$this->resetAfterTest();
|
||||
$context = \context_coursecat::instance($this->getDataGenerator()->create_category()->id);
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$questioncat = $questiongenerator->create_question_category(['contextid' => $context->id]);
|
||||
// Create a question.
|
||||
$question = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat->id]);
|
||||
// Add tag to question.
|
||||
\core_tag_tag::set_item_tags('core_question', 'question', $question->id,
|
||||
$context, ['Banana']);
|
||||
|
||||
// Retrieve the question text to display, including the tag, with the tag displayed as a link.
|
||||
$summary = quiz_question_tostring(question: $question, showtags: true);
|
||||
// Ensure the tag is enclosed within a link.
|
||||
$this->assertMatchesRegularExpression('/<a[^>]*>\s*Banana\s*<\/a>/', $summary);
|
||||
|
||||
// Retrieve the question text to display, including the tag, but ensure the tag is not displayed as a link.
|
||||
$summary = quiz_question_tostring(question: $question, showtags: true, displaytaglink: false);
|
||||
$this->assertMatchesRegularExpression('/<span[^>]*>\s*Banana\s*<\/span>/', $summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::quiz_question_tostring
|
||||
*/
|
||||
|
||||
@@ -39,6 +39,9 @@ This file describes API changes in the quiz code.
|
||||
quiz_grade_items and a new column quizgradeitemid in quiz_slots. There are new methods in structure grade_calculator
|
||||
and quiz_attempt to support this, and the new grades are shown on review.php, view.php and in some of the quiz reports.
|
||||
Also, the external functions get_attempt_review and get_user_attempts return the information about the extra grades if applicable.
|
||||
* The `quiz_question_tostring` method now includes a new boolean parameter, `displaytaglink`.
|
||||
This parameter specifies whether the tag name in the question bank should be displayed
|
||||
as a clickable hyperlink (`true`) or as plain text (`false`).
|
||||
|
||||
=== 4.3 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user