From 33d29d0d61893e11c8429e5b4538f634cd39892a Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Thu, 5 Dec 2024 15:11:02 +0700 Subject: [PATCH 1/2] MDL-75075 core_tag: Add an option to render tag lists without links --- .upgradenotes/MDL-75075-2024120507014897.yml | 15 ++++++++++++ lib/classes/output/core_renderer.php | 6 +++-- tag/classes/output/taglist.php | 14 ++++++++--- tag/templates/taglist.mustache | 25 +++++++++++++------- 4 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 .upgradenotes/MDL-75075-2024120507014897.yml diff --git a/.upgradenotes/MDL-75075-2024120507014897.yml b/.upgradenotes/MDL-75075-2024120507014897.yml new file mode 100644 index 00000000000..c03309233a9 --- /dev/null +++ b/.upgradenotes/MDL-75075-2024120507014897.yml @@ -0,0 +1,15 @@ +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 diff --git a/lib/classes/output/core_renderer.php b/lib/classes/output/core_renderer.php index 45442bbc61e..ba6680089a8 100644 --- a/lib/classes/output/core_renderer.php +++ b/lib/classes/output/core_renderer.php @@ -4521,6 +4521,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( @@ -4529,9 +4530,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/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 @@