Introduce new hook `ThemeLoader`

This commit is contained in:
Johannes Meyer 2022-05-11 10:48:39 +02:00
parent 0b9eecbabc
commit 2a80e8bca6
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
namespace Icinga\Application\Hook;
/**
* Provide an implementation of this hook to dynamically provide themes.
* Note that only the first registered hook is utilized. Also note that
* for ordinary themes this hook is not required. Place such in your
* module's theme path: <module-path>/public/css/themes
*/
abstract class ThemeLoaderHook
{
/**
* Get the path for the given theme
*
* @param ?string $theme
*
* @return ?string The path or NULL if the theme is unknown
*/
abstract public function getThemeFile(?string $theme): ?string;
}

View File

@ -290,6 +290,19 @@ class StyleSheet
$app = Icinga::app();
if ($theme && $theme !== self::DEFAULT_THEME) {
if (Hook::has('ThemeLoader')) {
try {
$path = Hook::first('ThemeLoader')->getThemeFile($theme);
} catch (Exception $e) {
Logger::error('Failed to call ThemeLoader hook: %s', $e);
$path = null;
}
if ($path !== null) {
return $path;
}
}
if (($pos = strpos($theme, '/')) !== false) {
$moduleName = substr($theme, 0, $pos);
$theme = substr($theme, $pos + 1);