add scripts via templates for independence from template renderer
This commit is contained in:
parent
22ac2bf970
commit
93120e5383
@ -33,21 +33,26 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServ
|
|||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRenderer;
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRenderer;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
class Loader
|
class Loader
|
||||||
{
|
{
|
||||||
protected Config $config;
|
protected Config $config;
|
||||||
protected Language $language;
|
protected Language $language;
|
||||||
|
protected Configuration $configuration;
|
||||||
|
|
||||||
public function __construct(Config $config, Language $language)
|
public function __construct(Config $config, Language $language)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
|
|
||||||
|
$this->configuration = oxNew( Configuration::class, $this );
|
||||||
|
$this->configuration->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FileException
|
|
||||||
*/
|
*/
|
||||||
public function getEditorCode(): string
|
public function getEditorCode(): string
|
||||||
{
|
{
|
||||||
@ -61,14 +66,12 @@ class Loader
|
|||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration = oxNew(Configuration::class, $this);
|
try {
|
||||||
$configuration->build();
|
|
||||||
|
|
||||||
$this->registerScripts($configuration);
|
|
||||||
$this->registerIncludes();
|
|
||||||
|
|
||||||
$engine = $this->getTemplateRenderer()->getTemplateEngine();
|
$engine = $this->getTemplateRenderer()->getTemplateEngine();
|
||||||
return $engine->render('@' . Constants::OXID_MODULE_ID.'/admin/editorswitch');
|
return $engine->render( '@' . Constants::OXID_MODULE_ID . '/admin/editorswitch' );
|
||||||
|
} catch ( NotFoundExceptionInterface|ContainerExceptionInterface) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,12 +79,16 @@ class Loader
|
|||||||
*/
|
*/
|
||||||
protected function isEnabledForCurrentController(): bool
|
protected function isEnabledForCurrentController(): bool
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
/** @var ModuleSettingService $service */
|
/** @var ModuleSettingService $service */
|
||||||
$service = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
|
$service = ContainerFactory::getInstance()->getContainer()->get( ModuleSettingServiceInterface::class );
|
||||||
/** @var string[] $aEnabledClasses */
|
/** @var string[] $aEnabledClasses */
|
||||||
$aEnabledClasses = $service->getCollection("aTinyMCE_classes", Constants::OXID_MODULE_ID);
|
$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 );
|
||||||
|
} catch (ContainerExceptionInterface|NotFoundExceptionInterface) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,55 +121,55 @@ class Loader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Configuration $configuration
|
* @return array
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
protected function registerScripts(Configuration $configuration): void
|
public function getScripts(): array
|
||||||
{
|
{
|
||||||
|
if (!$this->isEnabledForCurrentController()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$sCopyLongDescFromTinyMCE = file_get_contents(__DIR__.'/../../../assets/out/scripts/copyLongDesc.js');
|
$sCopyLongDescFromTinyMCE = file_get_contents(__DIR__.'/../../../assets/out/scripts/copyLongDesc.js');
|
||||||
$sUrlConverter = file_get_contents(__DIR__.'/../../../assets/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(),
|
$this->configuration->getConfig(),
|
||||||
(string) file_get_contents(__DIR__.'/../../../assets/out/scripts/init.js')
|
(string) file_get_contents(__DIR__.'/../../../assets/out/scripts/init.js')
|
||||||
);
|
);
|
||||||
|
|
||||||
$engine = $this->getTemplateRenderer()->getTemplateEngine();
|
return [
|
||||||
$globals = $engine->getGlobals();
|
$sCopyLongDescFromTinyMCE,
|
||||||
$sSuffix = ($globals['__oxid_include_dynamic']) ? '_dynamic' : '';
|
$sUrlConverter,
|
||||||
|
$sInit
|
||||||
$aScript = (array) Registry::getConfig()->getGlobalParameter('scripts' . $sSuffix);
|
];
|
||||||
|
|
||||||
$aScript[] = $sCopyLongDescFromTinyMCE;
|
|
||||||
$aScript[] = $sUrlConverter;
|
|
||||||
$aScript[] = $sInit;
|
|
||||||
|
|
||||||
Registry::getConfig()->setGlobalParameter('scripts' . $sSuffix, $aScript);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return array
|
||||||
* @throws FileException
|
|
||||||
*/
|
*/
|
||||||
protected function registerIncludes(): void
|
public function getIncludes(): array
|
||||||
{
|
{
|
||||||
$engine = $this->getTemplateRenderer()->getTemplateEngine();
|
if (!$this->isEnabledForCurrentController()) {
|
||||||
$globals = $engine->getGlobals();
|
return [];
|
||||||
$sSuffix = ($globals['__oxid_include_dynamic']) ? '_dynamic' : '';
|
|
||||||
|
|
||||||
/** @var array<int, string[]> $aInclude */
|
|
||||||
$aInclude = (array) Registry::getConfig()->getGlobalParameter('includes' . $sSuffix);
|
|
||||||
|
|
||||||
$aInclude[3][] = Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl(
|
|
||||||
Constants::OXID_MODULE_ID,
|
|
||||||
'assets/out/tinymce/tinymce.min.js'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
Registry::getConfig()->setGlobalParameter('includes' . $sSuffix, $aInclude);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return [
|
||||||
|
Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl(
|
||||||
|
Constants::OXID_MODULE_ID,
|
||||||
|
'out/tinymce/tinymce.min.js'
|
||||||
|
)
|
||||||
|
];
|
||||||
|
} catch (FileException) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TemplateRenderer
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
protected function getTemplateRenderer(): TemplateRenderer
|
protected function getTemplateRenderer(): TemplateRenderer
|
||||||
{
|
{
|
||||||
return ContainerFactory::getInstance()->getContainer()
|
return ContainerFactory::getInstance()->getContainer()
|
||||||
|
@ -23,6 +23,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
|
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
|
||||||
|
|
||||||
|
use O3\TinyMCE\Application\Model\Constants;
|
||||||
|
use OxidEsales\Eshop\Core\Exception\FileException;
|
||||||
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
|
||||||
class BaseUrl extends AbstractOption
|
class BaseUrl extends AbstractOption
|
||||||
{
|
{
|
||||||
protected string $key = 'base_url';
|
protected string $key = 'base_url';
|
||||||
@ -32,8 +36,14 @@ class BaseUrl extends AbstractOption
|
|||||||
*/
|
*/
|
||||||
public function get(): string
|
public function get(): string
|
||||||
{
|
{
|
||||||
return $this->loader->getShopConfig()->getActiveView()->getViewConfig()->getBaseDir() .
|
try {
|
||||||
'modules/o3-shop/tinymce-editor/out/tinymce/';
|
return Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl(
|
||||||
|
Constants::OXID_MODULE_ID,
|
||||||
|
'out/tinymce/'
|
||||||
|
);
|
||||||
|
} catch (FileException) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,22 +24,37 @@ declare(strict_types=1);
|
|||||||
namespace O3\TinyMCE\Application\Core;
|
namespace O3\TinyMCE\Application\Core;
|
||||||
|
|
||||||
use O3\TinyMCE\Application\Core\TinyMCE\Loader;
|
use O3\TinyMCE\Application\Core\TinyMCE\Loader;
|
||||||
use OxidEsales\Eshop\Core\Exception\FileException;
|
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
|
|
||||||
class ViewConfig extends ViewConfig_parent
|
class ViewConfig extends ViewConfig_parent
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FileException
|
|
||||||
*/
|
*/
|
||||||
public function loadTinyMce(): string
|
public function getTinyMceInitCode(): string
|
||||||
{
|
{
|
||||||
$config = Registry::getConfig();
|
$config = Registry::getConfig();
|
||||||
$language = Registry::getLang();
|
$language = Registry::getLang();
|
||||||
|
|
||||||
$loader = oxNew(Loader::class, $config, $language);
|
$loader = oxNew(Loader::class, $config, $language);
|
||||||
|
|
||||||
return $loader->getEditorCode();
|
return $loader->getEditorCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTinyMceScripts(): array
|
||||||
|
{
|
||||||
|
$config = Registry::getConfig();
|
||||||
|
$language = Registry::getLang();
|
||||||
|
|
||||||
|
$loader = oxNew(Loader::class, $config, $language);
|
||||||
|
return $loader->getScripts();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTinyMceIncludes(): array
|
||||||
|
{
|
||||||
|
$config = Registry::getConfig();
|
||||||
|
$language = Registry::getLang();
|
||||||
|
|
||||||
|
$loader = oxNew(Loader::class, $config, $language);
|
||||||
|
return $loader->getIncludes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
[{$smarty.block.parent}]
|
[{$smarty.block.parent}]
|
||||||
|
|
||||||
[{if method_exists($oViewConf,'loadTinyMce') }][{ $oViewConf->loadTinyMce() }][{/if}]
|
[{if method_exists($oViewConf,'getTinyMceIncludes') }]
|
||||||
|
[{foreach from=$oViewConf->getTinyMceIncludes() item="tmceinclude"}]
|
||||||
|
[{oxscript include=$tmceinclude}]
|
||||||
|
[{/foreach}]
|
||||||
|
[{/if}]
|
||||||
|
|
||||||
|
[{if method_exists($oViewConf,'getTinyMceScripts') }]
|
||||||
|
[{foreach from=$oViewConf->getTinyMceScripts() item="tmcescript"}]
|
||||||
|
[{oxscript add=$tmcescript}]
|
||||||
|
[{/foreach}]
|
||||||
|
[{/if}]
|
||||||
|
|
||||||
|
[{if method_exists($oViewConf,'getTinyMceInitCode') }]
|
||||||
|
[{ $oViewConf->getTinyMceInitCode() }]
|
||||||
|
[{/if}]
|
@ -4,8 +4,20 @@
|
|||||||
|
|
||||||
{{ parent() }}
|
{{ parent() }}
|
||||||
|
|
||||||
{% if method_exists(oViewConf,'loadTinyMce') %}
|
{% if method_exists(oViewConf,'getTinyMceIncludes') %}
|
||||||
{{ oViewConf.loadTinyMce()|raw }}
|
{% for tmceinclude in oViewConf.getTinyMceIncludes() %}
|
||||||
|
{{ script({ include: tmceinclude|raw }) }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if method_exists(oViewConf,'getTinyMceScripts') %}
|
||||||
|
{% for tmcescript in oViewConf.getTinyMceScripts() %}
|
||||||
|
{{ script({ add: tmcescript|raw }) }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if method_exists(oViewConf,'getTinyMceInitCode') %}
|
||||||
|
{{ oViewConf.getTinyMceInitCode()|raw }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user