MDL-77105 core: Add a filtericon parameter to course mod icon URLs

* If a plugin defines a `filtericon` custom data or uses its monologo
version of the icon, a `filtericon` parameter is being added to the
icon's URL. This information can help plugins determine whether to
render the activity icon as is or with CSS filtering.
This commit is contained in:
Jun Pataleta
2023-03-27 13:45:35 +08:00
parent 8812990c85
commit 0778d512fe
+21 -1
View File
@@ -1784,7 +1784,15 @@ class cm_info implements IteratorAggregate {
}
/**
* @param moodle_core_renderer $output Output render to use, or null for default (global)
* Fetch the module's icon URL.
*
* This function fetches the course module instance's icon URL.
* This method adds a `filtericon` parameter in the URL when rendering the monologo version of the course module icon or when
* the plugin declares, via its `filtericon` custom data, that the icon needs to be filtered.
* This additional information can be used by plugins when rendering the module icon to determine whether to apply
* CSS filtering to the icon.
*
* @param core_renderer $output Output render to use, or null for default (global)
* @return moodle_url Icon URL for a suitable icon to put beside this cm
*/
public function get_icon_url($output = null) {
@@ -1794,6 +1802,7 @@ class cm_info implements IteratorAggregate {
$output = $OUTPUT;
}
$ismonologo = false;
if (!empty($this->iconurl)) {
// Support modules setting their own, external, icon image.
$icon = $this->iconurl;
@@ -1813,6 +1822,17 @@ class cm_info implements IteratorAggregate {
}
} else {
$icon = $output->image_url('monologo', $this->modname);
// Activity modules may only have an `icon` icon instead of a `monologo` icon.
// So we need to determine if the module really has a `monologo` icon.
$ismonologo = core_component::has_monologo_icon('mod', $this->modname);
}
// Determine whether the icon will be filtered in the CSS.
// This can be controlled by the module by declaring a 'filtericon' custom data.
// If the 'filtericon' custom data is not set, icon filtering will be determined whether the module has a `monologo` icon.
$filtericon = $this->customdata['filtericon'] ?? $ismonologo;
if ($filtericon) {
$icon->param('filtericon', 1);
}
return $icon;
}