MDL-84954 calendar: add color to activity icons
This commit is contained in:
@@ -54,7 +54,10 @@
|
||||
<small class="text-end text-nowrap align-self-center ms-1">
|
||||
{{#userdate}} {{timesort}}, {{#str}} strftimetime24, core_langconfig {{/str}} {{/userdate}}
|
||||
</small>
|
||||
<div class="activityiconcontainer small courseicon align-self-top align-self-center mx-3 mb-1 mb-sm-0 text-nowrap">
|
||||
<div
|
||||
class="small courseicon align-self-top align-self-center mx-3 mb-1 mb-sm-0 text-nowrap {{!
|
||||
}} activityiconcontainer {{#purpose}}{{purpose}}{{/purpose}}"
|
||||
>
|
||||
{{#icon}}
|
||||
{{#iconurl}}
|
||||
<img alt="{{alttext}}" title="{{alttext}}" src="{{{ iconurl }}}" class="icon {{iconclass}}">
|
||||
|
||||
+12
-3
@@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core\external\exporter;
|
||||
use \core_calendar\local\event\entities\event_interface;
|
||||
use core_course\output\activity_icon;
|
||||
|
||||
/**
|
||||
* Class for displaying a calendar event's icon.
|
||||
@@ -63,19 +64,25 @@ class event_icon_exporter extends exporter {
|
||||
$isuserevent = ($user && !empty($userid));
|
||||
$iconurl = '';
|
||||
$iconclass = '';
|
||||
$purpose = '';
|
||||
|
||||
if ($isactivityevent) {
|
||||
$key = 'monologo';
|
||||
$component = $coursemodule->get('modname');
|
||||
|
||||
$iconurl = get_fast_modinfo($courseid)->get_cm($coursemodule->get('id'))->get_icon_url();
|
||||
$iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter';
|
||||
$iconurl = $iconurl->out(false);
|
||||
if (get_string_manager()->string_exists($event->get_type(), $component)) {
|
||||
$alttext = get_string($event->get_type(), $component);
|
||||
} else {
|
||||
$alttext = get_string('activityevent', 'calendar');
|
||||
}
|
||||
|
||||
$renderer = \core\di::get(\core\output\renderer_helper::class)->get_core_renderer();
|
||||
$activityicon = activity_icon::from_cm_info($coursemodule->get_proxied_instance())
|
||||
->set_title($alttext);
|
||||
|
||||
$iconurl = $activityicon->get_icon_url($renderer)->out(false);
|
||||
$iconclass = $activityicon->get_icon_classes($renderer);
|
||||
$purpose = $activityicon->get_purpose();
|
||||
} else if ($event->get_component()) {
|
||||
// Guess the icon and the title for the component event. By default display calendar icon and the
|
||||
// plugin name as the alttext.
|
||||
@@ -125,6 +132,7 @@ class event_icon_exporter extends exporter {
|
||||
$data->alttext = $alttext;
|
||||
$data->iconurl = $iconurl;
|
||||
$data->iconclass = $iconclass;
|
||||
$data->purpose = $purpose;
|
||||
|
||||
parent::__construct($data, $related);
|
||||
}
|
||||
@@ -141,6 +149,7 @@ class event_icon_exporter extends exporter {
|
||||
'alttext' => ['type' => PARAM_TEXT],
|
||||
'iconurl' => ['type' => PARAM_TEXT],
|
||||
'iconclass' => ['type' => PARAM_TEXT],
|
||||
'purpose' => ['type' => PARAM_TEXT],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,10 @@
|
||||
}} data-eventtype-{{normalisedeventtype}}="1"{{!
|
||||
}} data-region="event-item"{{!
|
||||
}}>
|
||||
<div class="activityiconcontainer small courseicon me-3">
|
||||
<div
|
||||
class="activityiconcontainer small courseicon me-3 {{!
|
||||
}}{{#purpose}}{{purpose}}{{/purpose}}"
|
||||
>
|
||||
{{#icon}}
|
||||
{{#iconurl}}
|
||||
<img alt="{{alttext}}" title="{{alttext}}" src="{{{ iconurl }}}" class="icon {{iconclass}}">
|
||||
|
||||
@@ -135,15 +135,9 @@ class activity_icon implements renderable, templatable {
|
||||
|
||||
#[\Override]
|
||||
public function export_for_template(renderer_base $output): array {
|
||||
if (!isset($this->iconurl)) {
|
||||
$this->iconurl = $this->get_icon_url($output);
|
||||
}
|
||||
$needfiltering = $this->colourize && $this->iconurl->get_param('filtericon');
|
||||
$iconclass = $needfiltering ? '' : 'nofilter';
|
||||
|
||||
$data = [
|
||||
'icon' => $this->iconurl,
|
||||
'iconclass' => $iconclass,
|
||||
'icon' => $this->get_icon_url($output),
|
||||
'iconclass' => $this->get_icon_classes($output),
|
||||
'modname' => $this->modname,
|
||||
'pluginname' => get_string('pluginname', 'mod_' . $this->modname),
|
||||
'purpose' => $this->purpose,
|
||||
@@ -165,6 +159,9 @@ class activity_icon implements renderable, templatable {
|
||||
* @return url
|
||||
*/
|
||||
public function get_icon_url(renderer_base $output): url {
|
||||
if (isset($this->iconurl)) {
|
||||
return $this->iconurl;
|
||||
}
|
||||
$icon = $output->image_url('monologo', $this->modname);
|
||||
// Legacy activity modules may only have an `icon` icon instead of a `monologo` icon.
|
||||
$ismonologo = component::has_monologo_icon('mod', $this->modname);
|
||||
@@ -174,6 +171,7 @@ class activity_icon implements renderable, templatable {
|
||||
// The name of the param is not colorize to preserve backward compatibility.
|
||||
$icon->param('filtericon', 1);
|
||||
}
|
||||
$this->iconurl = $icon;
|
||||
return $icon;
|
||||
}
|
||||
|
||||
@@ -213,6 +211,20 @@ class activity_icon implements renderable, templatable {
|
||||
return $this->extraclasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon classes.
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return string
|
||||
*/
|
||||
public function get_icon_classes(renderer_base $output): string {
|
||||
$result = 'activityicon icon';
|
||||
$iconurl = $this->get_icon_url($output);
|
||||
$needfiltering = $this->colourize && $iconurl->get_param('filtericon');
|
||||
$result .= ($needfiltering) ? '' : ' nofilter';
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon size.
|
||||
*
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
>
|
||||
<img
|
||||
src="{{{icon}}}"
|
||||
class="activityicon icon {{iconclass}}"
|
||||
class="{{iconclass}}"
|
||||
data-region="activity-icon"
|
||||
alt="{{#title}}{{#cleanstr}} activityicon, moodle, {{{pluginname}}} {{/cleanstr}}{{/title}}"
|
||||
{{#title}}title="{{{title}}}"{{/title}}
|
||||
|
||||
Reference in New Issue
Block a user