diff --git a/.upgradenotes/MDL-75075-2024120507014897.yml b/.upgradenotes/MDL-75075-2024120507014897.yml
new file mode 100644
index 00000000000..647f9a6c733
--- /dev/null
+++ b/.upgradenotes/MDL-75075-2024120507014897.yml
@@ -0,0 +1,21 @@
+issueNumber: MDL-75075
+notes:
+ core:
+ - message: >-
+ The `core_renderer::tag_list` function now has a new parameter named `displaylink`.
+ When `displaylink` is set to `true`, the tag name will be displayed as a clickable hyperlink.
+ Otherwise, it will be rendered as plain text.
+ type: changed
+ core_tag:
+ - message: >-
+ The `core_tag\taglist` class now includes a new property called `displaylink`,
+ which has a default value of `true`. When `displaylink` is set to `true`,
+ the tag name will be displayed as a clickable hyperlink. If `displaylink` is set to `false`,
+ the tag name will be rendered as plain text instead.
+ type: changed
+ mod_quiz:
+ - message: >-
+ 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`).
+ type: changed
diff --git a/lib/classes/output/core_renderer.php b/lib/classes/output/core_renderer.php
index befef431861..b8535061ffc 100644
--- a/lib/classes/output/core_renderer.php
+++ b/lib/classes/output/core_renderer.php
@@ -4553,6 +4553,7 @@ EOD;
* will be appended to the end, JS will toggle the rest of the tags
* @param context $pagecontext specify if needed to overwrite the current page context for the view tag link
* @param bool $accesshidelabel if true, the label should have class="accesshide" added.
+ * @param bool $displaylink Indicates whether the tag should be displayed as a link.
* @return string
*/
public function tag_list(
@@ -4561,9 +4562,10 @@ EOD;
$classes = '',
$limit = 10,
$pagecontext = null,
- $accesshidelabel = false
+ $accesshidelabel = false,
+ $displaylink = true,
) {
- $list = new taglist($tags, $label, $classes, $limit, $pagecontext, $accesshidelabel);
+ $list = new taglist($tags, $label, $classes, $limit, $pagecontext, $accesshidelabel, $displaylink);
return $this->render_from_template('core_tag/taglist', $list->export_for_template($this));
}
diff --git a/mod/quiz/classes/question/bank/question_name_text_column.php b/mod/quiz/classes/question/bank/question_name_text_column.php
index 41d4bad8cb2..5e7406d3035 100644
--- a/mod/quiz/classes/question/bank/question_name_text_column.php
+++ b/mod/quiz/classes/question/bank/question_name_text_column.php
@@ -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');
}
diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php
index 41ed9e9ddf0..24683412130 100644
--- a/mod/quiz/locallib.php
+++ b/mod/quiz/locallib.php
@@ -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.
diff --git a/mod/quiz/tests/locallib_test.php b/mod/quiz/tests/locallib_test.php
index fd30e24a82d..734353d38f3 100644
--- a/mod/quiz/tests/locallib_test.php
+++ b/mod/quiz/tests/locallib_test.php
@@ -121,6 +121,32 @@ final class locallib_test extends \advanced_testcase {
'What sort of INEQUALITY is x < y[?]' . "\n" . '', $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('/]*>\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('/]*>\s*Banana\s*<\/span>/', $summary);
+ }
+
/**
* @covers ::quiz_question_tostring
*/
diff --git a/tag/classes/output/taglist.php b/tag/classes/output/taglist.php
index dda618d7d19..6289997c60a 100644
--- a/tag/classes/output/taglist.php
+++ b/tag/classes/output/taglist.php
@@ -54,6 +54,9 @@ class taglist implements templatable {
/** @var int */
protected $limit;
+ /** @var bool */
+ protected $displaylink;
+
/**
* Constructor
*
@@ -65,15 +68,17 @@ class taglist implements templatable {
* will be appended to the end, JS will toggle the rest of the tags. 0 means no limit.
* @param context $pagecontext specify if needed to overwrite the current page context for the view tag link
* @param bool $accesshidelabel if true, the label should have class="accesshide" added.
+ * @param bool $displaylink Indicates whether the tag should be displayed as a link.
*/
public function __construct($tags, $label = null, $classes = '',
- $limit = 10, $pagecontext = null, $accesshidelabel = false) {
+ $limit = 10, $pagecontext = null, $accesshidelabel = false, $displaylink = true) {
global $PAGE;
$canmanagetags = has_capability('moodle/tag:manage', \context_system::instance());
$this->label = ($label === null) ? get_string('tags') : $label;
$this->accesshidelabel = $accesshidelabel;
$this->classes = $classes;
+ $this->displaylink = $displaylink;
$fromctx = $pagecontext ? $pagecontext->id :
(($PAGE->context->contextlevel == CONTEXT_SYSTEM) ? 0 : $PAGE->context->id);
@@ -87,8 +92,10 @@ class taglist implements templatable {
$this->tags[$idx]->flag = 1;
}
- $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx);
- $this->tags[$idx]->viewurl = $viewurl->out(false);
+ if ($displaylink) {
+ $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx);
+ $this->tags[$idx]->viewurl = $viewurl->out(false);
+ }
if (isset($tag->isstandard)) {
$this->tags[$idx]->isstandard = $tag->isstandard ? 1 : 0;
@@ -116,6 +123,7 @@ class taglist implements templatable {
'tagscount' => $cnt,
'overflow' => ($this->limit && $cnt > $this->limit) ? 1 : 0,
'classes' => $this->classes,
+ 'displaylink' => $this->displaylink,
);
}
}
diff --git a/tag/templates/taglist.mustache b/tag/templates/taglist.mustache
index f6f56c9c579..1edab856e16 100644
--- a/tag/templates/taglist.mustache
+++ b/tag/templates/taglist.mustache
@@ -41,7 +41,8 @@
"accesshidelabel": false,
"tagscount": 3,
"overflow": 1,
- "classes": "someadditionalclass"
+ "classes": "someadditionalclass",
+ "displaylink": false
}
}}
@@ -53,13 +54,21 @@
- {{/flag}}
+ {{#displaylink}}
+
+ {{#flag}}
+ {{name}}
+ {{/flag}}
+ {{^flag}}
+ {{name}}
+ {{/flag}}
+
+ {{/displaylink}}
+ {{^displaylink}}
+
+ {{name}}
+
+ {{/displaylink}}
{{/tags}}
{{#overflow}}