在SS 3.x中,我们可以使用以下代码通过Styles
下拉列表将自定义元素添加到HTMLEditorField
内容编辑器中。我的主要用途是将标准链接转换为样式按钮链接。
我们如何在SS 4.x中实现这一目标?
这就是在 3.x 中完成的方式
_config.php
<?php
$formats = array(
array(
'title' => 'Buttons'
),
array(
'title' => 'Custom Button',
'attributes' => array('class'=>'custom-btn'),
'selector' => 'a'
)
);
//Set the dropdown menu options
HtmlEditorConfig::get('cms')->setOption('style_formats',$formats);
看起来您需要做的就是创建一个editor.css
文件,将样式放入其中,然后将以下代码片段放入mysite/_config.php
文件中。
use SilverStripeFormsHTMLEditorTinyMCEConfig;
TinyMCEConfig::get('cms')
->addButtonsToLine(1, 'styleselect')
->setOption('importcss_append', true);
样式将自动添加到下拉列表中。
参考: https://docs.silverstripe.org/en/4/developer_guides/customising_the_admin_interface/typography/#custom-style-dropdown