Reputation: 649
I have added HtmlEditorConfig before a Content HTMLEditorField. The problem, is I need to refresh or reload the browser page to see my custom css setting...
My code :
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'));
My question : Is it possible to auto refresh HTMLEditorField to use HtmlEditorConfig setting when page or dataobject load? I can't use it in _config.php because I have a variable into my custom HtmlEditorConfig code.
Upvotes: 1
Views: 257
Reputation: 649
I have found the solution! There are another way to configure HTMLEditorConfig with some custom variables into. In /mysite/_config.php, it's not possible to add variables with HTMLEditorConfig. And including HTMLEditorConfig into Page class with HTMLEditorField is working only when refreshing the URL one time.
The solution is to extend LeftAndMain with a LeftAndMainExtension. There is my solution code :
/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');
}
}
It's very usefull for HTMLEditor customization to add subsites related CSS style files with Subsites modules.
Upvotes: 1