Merge branch 'MDL-75075-404' of https://github.com/NashTechOpenUniversity/moodle into MOODLE_404_STABLE
This commit is contained in:
@@ -4941,11 +4941,12 @@ 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($tags, $label = null, $classes = '', $limit = 10,
|
||||
$pagecontext = null, $accesshidelabel = false) {
|
||||
$list = new \core_tag\output\taglist($tags, $label, $classes, $limit, $pagecontext, $accesshidelabel);
|
||||
$pagecontext = null, $accesshidelabel = false, $displaylink = true) {
|
||||
$list = new \core_tag\output\taglist($tags, $label, $classes, $limit, $pagecontext, $accesshidelabel, $displaylink);
|
||||
return $this->render_from_template('core_tag/taglist', $list->export_for_template($this));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ information provided here is intended especially for developers.
|
||||
- `willReturnConsecutive`
|
||||
- `onConsecutive`
|
||||
Any plugin using these methods must update their uses.
|
||||
* 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.
|
||||
|
||||
* `\core\output\activity_header` now uses the `is_title_allowed()` method when setting the title in the constructor.
|
||||
This method has been improved to give priority to the 'notitle' option in the theme config for the current page layout,
|
||||
|
||||
@@ -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 @@ final 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 ===
|
||||
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@
|
||||
"accesshidelabel": false,
|
||||
"tagscount": 3,
|
||||
"overflow": 1,
|
||||
"classes": "someadditionalclass"
|
||||
"classes": "someadditionalclass",
|
||||
"displaylink": false
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -53,13 +54,21 @@
|
||||
<ul class="inline-list">
|
||||
{{#tags}}
|
||||
<li {{#overlimit}}class="overlimit"{{/overlimit}}>
|
||||
<a href="{{viewurl}}" class="badge bg-info text-white {{#isstandard}}standardtag{{/isstandard}}" >
|
||||
{{#flag}}
|
||||
<span class="flagged-tag">{{name}}</span></a>
|
||||
{{/flag}}
|
||||
{{^flag}}
|
||||
{{name}}</a>
|
||||
{{/flag}}
|
||||
{{#displaylink}}
|
||||
<a href="{{viewurl}}" class="badge bg-info text-white {{#isstandard}}standardtag{{/isstandard}}">
|
||||
{{#flag}}
|
||||
<span class="flagged-tag">{{name}}</span>
|
||||
{{/flag}}
|
||||
{{^flag}}
|
||||
{{name}}
|
||||
{{/flag}}
|
||||
</a>
|
||||
{{/displaylink}}
|
||||
{{^displaylink}}
|
||||
<span class="badge bg-info {{#flag}}flagged-tag{{/flag}} {{^flag}}text-white{{/flag}} {{#isstandard}}standardtag{{/isstandard}}">
|
||||
{{name}}
|
||||
</span>
|
||||
{{/displaylink}}
|
||||
</li>
|
||||
{{/tags}}
|
||||
{{#overflow}}
|
||||
|
||||
@@ -6,6 +6,9 @@ here is intended especially for developers.
|
||||
* New additional property 'viewurl' has been added to the pre-defined structure in tag_item_exporter. This property
|
||||
represents the URL to view a given tag.
|
||||
* The `core_tag_manage_table` class has been deprecated, in favour of new report builder implementation
|
||||
* 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.
|
||||
|
||||
=== 3.6 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user