diff --git a/apps/theming/lib/Service/ThemesService.php b/apps/theming/lib/Service/ThemesService.php
index 433555c980c74..39a8eeff41052 100644
--- a/apps/theming/lib/Service/ThemesService.php
+++ b/apps/theming/lib/Service/ThemesService.php
@@ -154,12 +154,15 @@ public function isEnabled(ITheme $theme): bool {
* @return string[]
*/
public function getEnabledThemes(): array {
+ $enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
$user = $this->userSession->getUser();
if ($user === null) {
+ if ($enforcedTheme !== '') {
+ return [$enforcedTheme];
+ }
return [];
}
- $enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
$enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '["default"]'));
if ($enforcedTheme !== '') {
return array_merge([$enforcedTheme], $enabledThemes);
diff --git a/core/templates/layout.public.php b/core/templates/layout.public.php
index bd46ee4f7fc7e..c39ebf35f33f3 100644
--- a/core/templates/layout.public.php
+++ b/core/templates/layout.public.php
@@ -36,7 +36,9 @@
-
+ data-themes="">
@@ -81,11 +83,11 @@
getHeaderTitle() !== '') {
- p($template->getHeaderTitle());
- } else {
- p($theme->getName());
- } ?>
+ if (isset($template) && $template->getHeaderTitle() !== '') {
+ p($template->getHeaderTitle());
+ } else {
+ p($theme->getName());
+ } ?>
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 2bc9ff5a2af74..e4978916ec365 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -158,6 +158,14 @@ public function __construct($renderAs, $appId = '') {
$this->assign('appid', $appId);
$this->assign('bodyid', 'body-public');
+ // Set body data-theme
+ $this->assign('enabledThemes', []);
+ if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) {
+ /** @var \OCA\Theming\Service\ThemesService $themesService */
+ $themesService = \OC::$server->get(\OCA\Theming\Service\ThemesService::class);
+ $this->assign('enabledThemes', $themesService->getEnabledThemes());
+ }
+
// Set logo link target
$logoUrl = $this->config->getSystemValueString('logo_url', '');
$this->assign('logoUrl', $logoUrl);