From e86cbd49bbbeb28015cf2fdf5949d98d0f0931a0 Mon Sep 17 00:00:00 2001 From: Marcus Fabriczy Date: Tue, 3 Apr 2018 12:44:16 +0930 Subject: [PATCH] MDL-60196 core_course: Fix the display of custom LTI icons Custom LTI icons attached to LTI tools did not display - a regression caused by MDL-55796. Change-Id: I02c5d9ff4738657100d020e406d391a449f7588b --- course/classes/output/modchooser_item.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/course/classes/output/modchooser_item.php b/course/classes/output/modchooser_item.php index e38956db30b..553e534c2b4 100644 --- a/course/classes/output/modchooser_item.php +++ b/course/classes/output/modchooser_item.php @@ -38,6 +38,9 @@ use pix_icon; */ class modchooser_item extends \core\output\chooser_item { + /** @var string */ + protected $customiconurl; + /** * Constructor. * @@ -50,10 +53,33 @@ class modchooser_item extends \core\output\chooser_item { 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; + } }