N°2314 - Markup extensibility: Fall back on iTop's default theme when a non existing theme is selected

This commit is contained in:
Stephen Abello
2020-02-03 15:11:08 +01:00
parent 6e927114e0
commit 10d04756ee
2 changed files with 44 additions and 26 deletions

View File

@@ -27,6 +27,29 @@ use ScssPhp\ScssPhp\Compiler;
*/
class ThemeHandler
{
/**
* Return default theme name and parameters
*
* @return array
* @since 2.7.0
*/
public static function GetDefaultThemeInformation()
{
return array(
'name' => 'light-grey',
'parameters' => array(
'variables' => array(),
'imports' => array(
'css-variables' => '../css/css-variables.scss',
),
'stylesheets' => array(
'jqueryui' => '../css/ui-lightness/jqueryui.scss',
'main' => '../css/light-grey.scss',
),
),
);
}
/**
* Return the absolute URL for the default theme CSS file
*
@@ -35,8 +58,26 @@ class ThemeHandler
*/
public static function GetDefaultThemeUrl()
{
$sThemeId = MetaModel::GetConfig()->Get('backoffice_default_theme');
static::CompileTheme($sThemeId);
try
{
$sThemeId = MetaModel::GetConfig()->Get('backoffice_default_theme');
static::CompileTheme($sThemeId);
}
catch(CoreException $oCompileException)
{
// Fallback on our default theme (should always be compilable)
$aDefaultTheme = ThemeHandler::GetDefaultThemeInformation();
$sThemeId = $aDefaultTheme['name'];
$sDefaultThemeDirPath = APPROOT.'env-'.utils::GetCurrentEnvironment().'/branding/themes/'.$sThemeId.'/';
// Create our theme dir if it doesn't exist (XML theme node removed, renamed etc..)
if(!is_dir($sDefaultThemeDirPath))
{
SetupUtils::builddir($sDefaultThemeDirPath);
}
static::CompileTheme($sThemeId, $aDefaultTheme['parameters']);
}
// Return absolute url to theme compiled css
return utils::GetAbsoluteUrlModulesRoot().'/branding/themes/'.$sThemeId.'/main.css';

View File

@@ -2737,7 +2737,7 @@ EOF;
// Force to have a default theme if none in the DM
if(empty($aThemes))
{
$aDefaultThemeInfo = $this->GetDefaultThemeInformation();
$aDefaultThemeInfo = ThemeHandler::GetDefaultThemeInformation();
$aThemes[$aDefaultThemeInfo['name']] = $aDefaultThemeInfo['parameters'];
}
@@ -2755,29 +2755,6 @@ EOF;
}
}
/**
* Return default theme name and parameters
*
* @return array
* @since 2.7.0
*/
protected function GetDefaultThemeInformation()
{
return array(
'name' => 'light-grey',
'parameters' => array(
'variables' => array(),
'imports' => array(
'css-variables' => '../css/css-variables.scss',
),
'stylesheets' => array(
'jqueryui' => '../css/ui-lightness/jqueryui.scss',
'main' => '../css/light-grey.scss',
),
),
);
}
/**
* @param \MFElement $oBrandingNode
* @param string $sTempTargetDir