can render Twig template

This commit is contained in:
Daniel Seifert 2024-12-03 16:00:24 +01:00
parent 3a86b6e947
commit 22ac2bf970
8 changed files with 37 additions and 18 deletions

View File

@ -28,5 +28,5 @@ use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
class TinyFileManager extends AdminController class TinyFileManager extends AdminController
{ {
protected $_sThisTemplate = '@' . Constants::OXID_MODULE_ID.'/admin/TinyFilemanager.tpl'; protected $_sThisTemplate = '@' . Constants::OXID_MODULE_ID.'/admin/tinyfilemanager';
} }

View File

@ -28,6 +28,11 @@ use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\FileException; use OxidEsales\Eshop\Core\Exception\FileException;
use OxidEsales\Eshop\Core\Language; use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRenderer;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
class Loader class Loader
{ {
@ -62,8 +67,8 @@ class Loader
$this->registerScripts($configuration); $this->registerScripts($configuration);
$this->registerIncludes(); $this->registerIncludes();
$smarty = Registry::getUtilsView()->getSmarty(); $engine = $this->getTemplateRenderer()->getTemplateEngine();
return $smarty->fetch('@' . Constants::OXID_MODULE_ID.'/admin/EditorSwitch.tpl'); return $engine->render('@' . Constants::OXID_MODULE_ID.'/admin/editorswitch');
} }
/** /**
@ -71,8 +76,10 @@ class Loader
*/ */
protected function isEnabledForCurrentController(): bool protected function isEnabledForCurrentController(): bool
{ {
/** @var ModuleSettingService $service */
$service = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
/** @var string[] $aEnabledClasses */ /** @var string[] $aEnabledClasses */
$aEnabledClasses = $this->getShopConfig()->getConfigParam("aTinyMCE_classes", []); $aEnabledClasses = $service->getCollection("aTinyMCE_classes", Constants::OXID_MODULE_ID);
return in_array($this->getShopConfig()->getActiveView()->getClassKey(), $aEnabledClasses); return in_array($this->getShopConfig()->getActiveView()->getClassKey(), $aEnabledClasses);
} }
@ -113,22 +120,25 @@ class Loader
*/ */
protected function registerScripts(Configuration $configuration): void protected function registerScripts(Configuration $configuration): void
{ {
$sCopyLongDescFromTinyMCE = file_get_contents(__DIR__.'/../../../out/scripts/copyLongDesc.js'); $sCopyLongDescFromTinyMCE = file_get_contents(__DIR__.'/../../../assets/out/scripts/copyLongDesc.js');
$sUrlConverter = file_get_contents(__DIR__.'/../../../out/scripts/urlConverter.js'); $sUrlConverter = file_get_contents(__DIR__.'/../../../assets/out/scripts/urlConverter.js');
$sInit = str_replace( $sInit = str_replace(
"'CONFIG':'VALUES'", "'CONFIG':'VALUES'",
$configuration->getConfig(), $configuration->getConfig(),
(string) file_get_contents(__DIR__.'/../../../out/scripts/init.js') (string) file_get_contents(__DIR__.'/../../../assets/out/scripts/init.js')
); );
$smarty = Registry::getUtilsView()->getSmarty();
$sSufix = ($smarty->_tpl_vars["__oxid_include_dynamic"]) ? '_dynamic' : '';
$aScript = (array) Registry::getConfig()->getGlobalParameter('scripts' . $sSufix); $engine = $this->getTemplateRenderer()->getTemplateEngine();
$globals = $engine->getGlobals();
$sSuffix = ($globals['__oxid_include_dynamic']) ? '_dynamic' : '';
$aScript = (array) Registry::getConfig()->getGlobalParameter('scripts' . $sSuffix);
$aScript[] = $sCopyLongDescFromTinyMCE; $aScript[] = $sCopyLongDescFromTinyMCE;
$aScript[] = $sUrlConverter; $aScript[] = $sUrlConverter;
$aScript[] = $sInit; $aScript[] = $sInit;
Registry::getConfig()->setGlobalParameter('scripts' . $sSufix, $aScript); Registry::getConfig()->setGlobalParameter('scripts' . $sSuffix, $aScript);
} }
/** /**
@ -137,17 +147,26 @@ class Loader
*/ */
protected function registerIncludes(): void protected function registerIncludes(): void
{ {
$smarty = Registry::getUtilsView()->getSmarty(); $engine = $this->getTemplateRenderer()->getTemplateEngine();
$sSuffix = ($smarty->_tpl_vars["__oxid_include_dynamic"]) ? '_dynamic' : ''; $globals = $engine->getGlobals();
$sSuffix = ($globals['__oxid_include_dynamic']) ? '_dynamic' : '';
/** @var array<int, string[]> $aInclude */ /** @var array<int, string[]> $aInclude */
$aInclude = (array) Registry::getConfig()->getGlobalParameter('includes' . $sSuffix); $aInclude = (array) Registry::getConfig()->getGlobalParameter('includes' . $sSuffix);
$aInclude[3][] = Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl( $aInclude[3][] = Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl(
'o3-tinymce-editor', Constants::OXID_MODULE_ID,
'out/tinymce/tinymce.min.js' 'assets/out/tinymce/tinymce.min.js'
); );
Registry::getConfig()->setGlobalParameter('includes' . $sSuffix, $aInclude); Registry::getConfig()->setGlobalParameter('includes' . $sSuffix, $aInclude);
} }
protected function getTemplateRenderer(): TemplateRenderer
{
return ContainerFactory::getInstance()->getContainer()
->get(TemplateRendererBridgeInterface::class)
->getTemplateRenderer();
}
} }

View File

@ -40,8 +40,8 @@ $aModule = [
'tinyfilemanager' => O3\TinyMCE\Application\Controller\Admin\TinyFileManager::class, 'tinyfilemanager' => O3\TinyMCE\Application\Controller\Admin\TinyFileManager::class,
], ],
'templates' => [ 'templates' => [
'@' . Constants::OXID_MODULE_ID.'/admin/TinyFilemanager.tpl' => 'views/smarty/admin/tpl/filemanager.tpl', '@' . Constants::OXID_MODULE_ID.'/admin/tinyfilemanager.tpl' => 'views/smarty/admin/filemanager.tpl',
'@' . Constants::OXID_MODULE_ID.'/admin/EditorSwitch.tpl' => 'views/smarty/admin/tpl/editorswitch.tpl', '@' . Constants::OXID_MODULE_ID.'/admin/editorswitch.tpl' => 'views/smarty/admin/editorswitch.tpl',
], ],
'blocks' => [ 'blocks' => [
[ [

View File

@ -5,7 +5,7 @@
{{ parent() }} {{ parent() }}
{% if method_exists(oViewConf,'loadTinyMce') %} {% if method_exists(oViewConf,'loadTinyMce') %}
{{ oViewConf.loadTinyMce() }} {{ oViewConf.loadTinyMce()|raw }}
{% endif %} {% endif %}
{% endblock %} {% endblock %}