Skip to content

Commit

Permalink
Merge branch 'MDL-60196_33' of https://github.com/mfabriczy/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_33_STABLE
  • Loading branch information
stronk7 committed Apr 9, 2018
2 parents f9c68b4 + a83ceb2 commit 61ab947
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions course/classes/output/modchooser_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
class modchooser_item extends \core\output\chooser_item {

/** @var string */
protected $customiconurl;

/**
* Constructor.
*
Expand All @@ -50,10 +53,33 @@ public function __construct($module, context $context) {
if ($colon = strpos($modulename, ':')) {
$modulename = substr($modulename, 0, $colon);
}
if (preg_match('/src="([^"]*)"/i', $module->icon, $matches)) {
// Use the custom icon.
$this->customiconurl = str_replace('&', '&', $matches[1]);
}

$icon = new pix_icon('icon', '', $modulename, ['class' => 'icon']);
$help = isset($module->help) ? $module->help : new lang_string('nohelpforactivityorresource', 'moodle');

parent::__construct($module->name, $module->title, $module->link->out(false), $icon, $help, $context);
}

/**
* Export for template.
*
* @param \renderer_base $output The renderer
* @return \stdClass $data
*/
public function export_for_template(\renderer_base $output) {
$data = parent::export_for_template($output);
if ($this->customiconurl && !empty($data->icon['attributes'])) {
// Replace icon source with a module-provided icon.
foreach ($data->icon['attributes'] as &$attribute) {
if ($attribute['name'] === 'src') {
$attribute['value'] = $this->customiconurl;
}
}
}
return $data;
}
}

0 comments on commit 61ab947

Please sign in to comment.