diff --git a/application/models/QuestionTemplate.php b/application/models/QuestionTemplate.php index c42d339054f..a2df458b05f 100644 --- a/application/models/QuestionTemplate.php +++ b/application/models/QuestionTemplate.php @@ -411,7 +411,6 @@ static public function getQuestionTemplateUserList($type) // Get the config file and check if template is available $oConfig = self::getTemplateConfig($sFullPathToQuestionTemplate); - if (is_object($oConfig) && isset($oConfig->engine->show_as_template) && $oConfig->engine->show_as_template) { if (!empty($oConfig->metadata->title)){ $aQuestionTemplates[$file]['title'] = json_decode(json_encode($oConfig->metadata->title), TRUE)[0]; @@ -419,11 +418,18 @@ static public function getQuestionTemplateUserList($type) $templateName = $file; $aQuestionTemplates[$file]['title'] = $templateName; } - if (!empty($oConfig->files->preview->filename)){ - $aQuestionTemplates[$file]['preview'] = json_decode(json_encode($oConfig->files->preview->filename), TRUE)[0]; - } else { - $aQuestionTemplates[$file]['preview'] = \LimeSurvey\Helpers\questionHelper::getQuestionThemePreviewUrl($type); + $fileName = json_decode(json_encode($oConfig->files->preview->filename), TRUE)[0]; + $previewPath = $sFullPathToQuestionTemplate."/assets/".$fileName; + if(is_file($previewPath) && LSYii_ImageValidator::validateImage($previewPath)) { + $aQuestionTemplates[$file]['preview'] = App()->getAssetManager()->publish($previewPath); + } else { + /* Log it a theme.question.$oConfig->name as error, review ? */ + Yii::log("Unable to use $fileName for preview in $sFullPathToQuestionTemplate/assets/",'error','theme.question.'.$oConfig->metadata->name); + } + } + if(empty($aQuestionTemplates[$file]['preview'])) { + $aQuestionTemplates[$file]['preview'] = $aQuestionTemplates['core']['preview']; } } }