diff --git a/lib/pagelib.php b/lib/pagelib.php index d1a5d780601..64f4621b0f1 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1560,16 +1560,22 @@ class moodle_page { } } + $devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse); + + // The user is using another device than default, and we have a theme for that, we should use it. + $hascustomdevicetheme = core_useragent::DEVICETYPE_DEFAULT != $this->devicetypeinuse && !empty($devicetheme); + foreach ($themeorder as $themetype) { + switch ($themetype) { case 'course': - if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && $this->devicetypeinuse == 'default') { + if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) { return $this->_course->theme; } break; case 'category': - if (!empty($CFG->allowcategorythemes) && $this->devicetypeinuse == 'default') { + if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) { $categories = $this->categories; foreach ($categories as $category) { if (!empty($category->theme)) { @@ -1586,7 +1592,7 @@ class moodle_page { break; case 'user': - if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && $this->devicetypeinuse == 'default') { + if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) { if ($mnetpeertheme) { return $mnetpeertheme; } else { @@ -1600,12 +1606,11 @@ class moodle_page { return $mnetpeertheme; } // First try for the device the user is using. - $devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse); if (!empty($devicetheme)) { return $devicetheme; } // Next try for the default device (as a fallback). - $devicetheme = core_useragent::get_device_type_theme('default'); + $devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT); if (!empty($devicetheme)) { return $devicetheme; }