跳到内容

定义可重用配置

编辑此页

CKEditor 捆绑包提供高级配置,可在多个 CKEditor 实例上重复使用。您可以一次性配置并在所有时间重复使用它,而不是在每个表单构建器上复制配置。该捆绑包允许您根据需要定义任意数量的配置。

提示

查看 CKEditor 配置选项 的完整列表。

定义配置

1
2
3
4
5
6
7
8
9
# app/config/config.yml
fos_ck_editor:
    configs:
        my_config:
            toolbar: [ ["Source", "-", "Save"], "/", ["Anchor"], "/", ["Maximize"] ]
            uiColor:                "#000000"
            filebrowserUploadRoute: "my_route"
            extraPlugins:           "wordcount"
            # ...

提示

config 节点是一个变量节点,意味着您可以将任何 CKEditor 配置选项放入其中。

注意

如果您没有明确配置,则定义的第一个配置将用作默认配置。

使用配置

定义配置后,您可以使用 config_name 选项来使用它

1
2
3
$builder->add('field', 'ckeditor', [
    'config_name' => 'my_config',
]);

覆盖配置

如果您想覆盖已定义配置的某些部分,您仍然可以使用 config 选项

1
2
3
4
$builder->add('field', 'ckeditor', [
    'config_name' => 'my_config',
    'config'      => ['uiColor' => '#ffffff'],
]);

定义默认配置

如果您想全局定义配置以默认使用它,而无需使用 config_name 选项,则可以使用 default_config 节点

1
2
3
4
5
6
# app/config/config.yml
fos_ck_editor:
    default_config: my_config
    configs:
        my_config:
            # ...
这项工作,包括代码示例,均根据 Creative Commons BY-SA 3.0 许可获得许可。
目录
    版本