From 704153c45461cb1d2caa35c0d84258b461d25637 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 22 Jun 2020 15:09:15 +0200 Subject: [PATCH 1/2] MDL-69109 core: use different cache keys for FA icon maps --- lib/classes/output/icon_system_fontawesome.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/classes/output/icon_system_fontawesome.php b/lib/classes/output/icon_system_fontawesome.php index c9dca916837..dcd18da1220 100644 --- a/lib/classes/output/icon_system_fontawesome.php +++ b/lib/classes/output/icon_system_fontawesome.php @@ -434,7 +434,10 @@ class icon_system_fontawesome extends icon_system_font { if ($this->map === []) { $cache = \cache::make('core', 'fontawesomeiconmapping'); - $this->map = $cache->get('mapping'); + // Create different mapping keys for different icon system classes, there may be several different + // themes on the same site. + $mapkey = 'mapping_'.preg_replace('/[^a-zA-Z0-9_]/', '_', get_class($this)); + $this->map = $cache->get($mapkey); if (empty($this->map)) { $this->map = $this->get_core_icon_map(); @@ -448,7 +451,7 @@ class icon_system_fontawesome extends icon_system_font { } } } - $cache->set('mapping', $this->map); + $cache->set($mapkey, $this->map); } } From d690ed3dd3ad6c511354b6ccf20261200d237ebf Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 23 Jun 2020 16:02:33 +0200 Subject: [PATCH 2/2] MDL-69109 theme: try to load icons from the current theme --- lib/classes/output/icon_system.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/classes/output/icon_system.php b/lib/classes/output/icon_system.php index 08e88b54d2e..14e1075c2d7 100644 --- a/lib/classes/output/icon_system.php +++ b/lib/classes/output/icon_system.php @@ -72,22 +72,22 @@ abstract class icon_system { /** * Factory method * - * @param $type Either a specific type, or null to get the default type. + * @param string $type Either a specific type, or null to get the default type. * @return \core\output\icon_system */ public final static function instance($type = null) { global $PAGE; - if ($type == null) { - if (!empty(self::$instance)) { - return self::$instance; - } - $type = $PAGE->theme->get_icon_system(); - self::$instance = new $type(); - // Default one is a singleton. + if (empty(self::$instance)) { + $icontype = $PAGE->theme->get_icon_system(); + self::$instance = new $icontype(); + } + + // If $type is specified we need to make sure that the theme icon system supports this type, + // if not, we will return a generic new instance of the $type. + if ($type === null || is_a(self::$instance, $type)) { return self::$instance; } else { - // Not a singleton. return new $type(); } }