MDL-87117 course: Add support in activity chooser to summary and tip

This commit is contained in:
Sara Arjona
2025-12-01 10:19:29 +01:00
parent fb206b336c
commit 1baacc2be6
12 changed files with 72 additions and 8 deletions
@@ -0,0 +1,8 @@
issueNumber: MDL-87117
notes:
core_course:
- message: >-
Two optional new strings, `modulename_summary` and `modulename_tip`,
have been added to modules and will be displayed in the activity chooser
interface when defined.
type: improved
@@ -48,6 +48,7 @@ class content_item {
* @param bool $branded whether or not this item is branded.
* @param bool $gradable whether or not this item is gradable.
* @param string|null $otherpurpose the alternative purpose type of this component.
* @param string|null $summary a brief summary of this content item.
*/
public function __construct(
/** @var int $id the id. */
@@ -74,6 +75,8 @@ class content_item {
private bool $gradable = false,
/** @var string|null $otherpurpose the alternative purpose type of this component. */
private ?string $otherpurpose = null,
/** @var string|null $summary a brief summary of this content item. */
private ?string $summary = null,
) {
}
@@ -183,4 +186,13 @@ class content_item {
public function is_gradable(): bool {
return $this->gradable;
}
/**
* Get a brief summary for this content item.
*
* @return string|null
*/
public function get_summary(): ?string {
return $this->summary;
}
}
@@ -66,6 +66,7 @@ class course_content_item_exporter extends exporter {
'link' => ['type' => PARAM_URL, 'description' => 'The link to the content item creation page'],
'icon' => ['type' => PARAM_RAW, 'description' => 'Html containing the icon for the content item'],
'help' => ['type' => PARAM_RAW, 'description' => 'Html description / help for the content item'],
'summary' => ['type' => PARAM_RAW, 'description' => 'Html summary for the content item'],
'archetype' => ['type' => PARAM_RAW, 'description' => 'The archetype of the module exposing the content item'],
'componentname' => ['type' => PARAM_TEXT, 'description' => 'The name of the component exposing the content item'],
'purpose' => ['type' => PARAM_TEXT, 'description' => 'The purpose of the component exposing the content item'],
@@ -140,8 +141,9 @@ class course_content_item_exporter extends exporter {
'title' => $this->contentitem->get_title()->get_value(),
'link' => $this->contentitem->get_link()->out(false),
'icon' => $this->contentitem->get_icon(),
// Help text should not be parsed using course filters.
// Help text, summary and tip should not be parsed using course filters.
'help' => format_text($this->contentitem->get_help(), FORMAT_MARKDOWN, ['filter' => false]),
'summary' => format_text($this->contentitem->get_summary(), FORMAT_MARKDOWN, ['filter' => false]),
'archetype' => $this->contentitem->get_archetype(),
'componentname' => $this->contentitem->get_component_name(),
'favourite' => $favourite,
@@ -50,6 +50,12 @@ class content_item_readonly_repository implements content_item_readonly_reposito
$sm = get_string_manager();
if ($sm->string_exists('modulename_help', $modname)) {
$help = get_string('modulename_help', $modname);
if ($sm->string_exists('modulename_tip', $modname)) {
$tipcontent = get_string('modulename_tip', $modname);
$tipicon = $OUTPUT->pix_icon('i/tip', '');
$tip = $tipicon . get_string('tip', '', $tipcontent);
$help .= \html_writer::tag('div', $tip, ['class' => 'helpdoctip alert alert-secondary']);
}
if ($sm->string_exists('modulename_link', $modname)) { // Link to further info in Moodle docs.
// The link is stored in a language file but should not be translated, use value for English.
$link = $sm->get_string('modulename_link', $modname, null, 'en');
@@ -57,12 +63,27 @@ class content_item_readonly_repository implements content_item_readonly_reposito
$linktext = get_string('morehelp');
$arialabel = get_string('morehelpaboutmodule', '', get_string('modulename', $modname));
$doclink = $OUTPUT->doc_link($link, $linktext, true, ['aria-label' => $arialabel]);
$help .= \html_writer::tag('div', $doclink, ['class' => 'helpdoclink']);
$help .= \html_writer::tag('div', $doclink, ['class' => 'helpdoclink opacity-75 pt-3']);
}
}
return $help;
}
/**
* Get the summary string for content items representing core modules.
*
* @param string $modname the module name.
* @return string the summary string or empty string if none exists.
*/
private function get_core_module_summary_string(string $modname): string {
$sm = get_string_manager();
if (!$sm->string_exists('modulename_summary', $modname)) {
return '';
}
return get_string('modulename_summary', $modname);
}
/**
* Helper to get the contentitems from all subplugin hooks for a given module plugin.
*
@@ -145,6 +166,7 @@ class content_item_readonly_repository implements content_item_readonly_reposito
// Create the content item for the module itself.
// If the module chooses to implement the hook, this may be thrown away.
$help = $this->get_core_module_help_string($mod->name);
$summary = $this->get_core_module_summary_string($mod->name);
$archetype = plugin_supports('mod', $mod->name, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
$purpose = plugin_supports('mod', $mod->name, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER);
$otherpurpose = plugin_supports('mod', $mod->name, FEATURE_MOD_OTHERPURPOSE);
@@ -164,6 +186,7 @@ class content_item_readonly_repository implements content_item_readonly_reposito
branded: $isbranded,
gradable: $gradable,
otherpurpose: $otherpurpose,
summary: $summary,
);
$modcontentitemreference = clone($contentitem);
@@ -215,6 +238,7 @@ class content_item_readonly_repository implements content_item_readonly_reposito
// Create the content item for the module itself.
// If the module chooses to implement the hook, this may be thrown away.
$help = $this->get_core_module_help_string($mod->name);
$summary = $this->get_core_module_summary_string($mod->name);
$archetype = plugin_supports('mod', $mod->name, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
$purpose = plugin_supports('mod', $mod->name, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER);
$otherpurpose = plugin_supports('mod', $mod->name, FEATURE_MOD_OTHERPURPOSE);
@@ -242,6 +266,7 @@ class content_item_readonly_repository implements content_item_readonly_reposito
branded: $isbranded,
gradable: $gradable,
otherpurpose: $otherpurpose,
summary: $summary,
);
$modcontentitemreference = clone($contentitem);
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -516,8 +516,9 @@ class ActivityChooserDialogue {
const searchResults = [];
this.mappedModules.forEach((activity) => {
const activityName = activity.title.toLowerCase();
const activitySummary = activity.summary.toLowerCase();
const activityDesc = activity.help.toLowerCase();
if (activityName.includes(searchTerm) || activityDesc.includes(searchTerm)) {
if (activityName.includes(searchTerm) || activitySummary.includes(searchTerm) || activityDesc.includes(searchTerm)) {
searchResults.push(activity);
}
});
@@ -27,6 +27,7 @@
"link": "http://yourmoodle/modedit.php?id=x&itemtype=y",
"icon": "<img class='icon' src='http://urltooptionicon' alt='Icon'>",
"help": "This is a description of the assignment activity",
"summary": "This is a summary of the assignment activity",
"archetype": 0,
"componentname": "mod_assign",
"favourite": 1,
@@ -51,7 +52,7 @@
data-region="summary-header"
tabindex="0"
>
<h6 class="h3 d-flex align-self-stretch align-items-center mb-4 gap-2">
<h6 class="h4 d-flex align-self-stretch align-items-center mb-4 gap-2">
<span
class="modicon_{{name}} activityiconcontainer smaller {{!
}} {{purpose}} {{#branded}}isbranded{{/branded}}"
@@ -106,13 +107,18 @@
</div>
{{! Repsonsive divider. }}
<hr class="d-block d-md-none my-2">
{{! General helps text. }}
{{! General text. }}
<div
class="flex-grow-1 pe-md-5"
id="optionsumary_desc-{{uniqid}}"
tabindex="0"
>
{{{help}}}
<div class="optionsummary-summary">
{{{summary}}}
</div>
<div class="optionsummary-help">
{{{help}}}
</div>
</div>
</div>
</div>
+1
View File
@@ -2269,6 +2269,7 @@ $string['time'] = 'Time';
$string['timecreated'] = 'Time created';
$string['timecreatedcourse'] = 'Course time created';
$string['timezone'] = 'Timezone';
$string['tip'] = '<strong>Tip</strong>: {$a}';
$string['todate'] = 'To';
$string['torecipient'] = 'To';
$string['tocreatenewaccount'] = 'Skip to create new account';
@@ -240,6 +240,9 @@
border-bottom: $border-width $border-style $border-color;
}
}
.optionsummary-summary {
font-size: larger;
}
}
/* Make modchooser modal full height and scrollable on small screens. */
+3
View File
@@ -31927,6 +31927,9 @@ table.calendartable caption {
padding-bottom: 1.5rem;
border-bottom: 1px solid #dee2e6;
}
.modchooser .optionsummary .optionsummary-summary {
font-size: larger;
}
/* Make modchooser modal full height and scrollable on small screens. */
@media (max-width: 575.98px) {
+3
View File
@@ -31927,6 +31927,9 @@ table.calendartable caption {
padding-bottom: 1.5rem;
border-bottom: 1px solid #dee2e6;
}
.modchooser .optionsummary .optionsummary-summary {
font-size: larger;
}
/* Make modchooser modal full height and scrollable on small screens. */
@media (max-width: 575.98px) {