SilverStripe 3.2 HTMLEditorField 使用 HtmlEditorConfig 自定义 css 样式

SilverStripe 3.2 HTMLEditorField customize css style with HtmlEditorConfig

我在 Content HTMLEditorField 之前添加了 HtmlEditorConfig。问题是我需要刷新或重新加载浏览器页面才能看到我的自定义 css 设置...

我的代码:

HtmlEditorConfig::get('cms')->setOption('content_css', '/themes/simple/css/test'.$this->variable.'.css, /themes/simple/css/typography.css');
$fields->addFieldsToTab("Root.Main", new HTMLEditorField('Content', 'Content'));            

我的问题:加载页面或数据对象时是否可以自动刷新 HTMLEditorField 以使用 HtmlEditorConfig 设置?我无法在 _config.php 中使用它,因为我的自定义 HtmlEditorConfig 代码中有一个变量。

我找到解决办法了!还有另一种方法可以使用一些自定义变量来配置 HTMLEditorConfig。在 /mysite/_config.php 中,无法使用 HTMLEditorConfig 添加变量。将 HTMLEditorConfig 包含到页面 class 和 HTMLEditorField 仅在刷新 URL 一次时有效。

解决方案是使用 LeftAndMainExtension 扩展 LeftAndMain。这是我的解决方案代码:

/mysite/_config.php

Object::add_extension("LeftAndMain", "HTMLEditorConfigSubsitesInit");

/mysite/code/HTMLEditorConfigSubsitesInit.php

class HTMLEditorConfigSubsitesInit extends LeftAndMainExtension
{
    function init()
    {

        $SiteConfig=SiteConfig::get()->filter('SubsiteID', Subsite::currentSubsiteID() )->First();
        $stripedMainFont = str_replace(" ", "-", $SiteConfig->MainFont );

        HtmlEditorConfig::get('cms')->setOption('content_css', '/mysite/css/fonts_'.$stripedMainFont.'.css, /assets/Subsite'.Subsite::currentSubsiteID().'/_customstyles.css, /themes/'.$SiteConfig->Theme.'/css/typography.css');

    }
}

使用 Subsites 模块添加与 CSS 样式文件相关的子站点对于 HTMLEditor 自定义非常有用。