trsteel/ckeditor-bundle

Symfony 扩展包,用于轻松集成 CKEditor WYSIWYG 编辑器

安装数: 570,965

依赖关系: 13

建议者: 21

安全: 0

星标: 97

关注者: 11

分支: 59

开放问题: 0

类型:symfony-bundle

1.21.1 2024-02-09 01:10 UTC

README

  1. 将 TrsteelCkeditorBundle 添加到您的 composer.json 文件中
  2. 启用该扩展包
  3. 安装扩展包资源
  4. 配置扩展包(可选)
  5. 将编辑器添加到表单中
  6. 配置数据转换器

步骤 1: 将 TrsteelCkeditorBundle 添加到您的 composer.json

php composer.phar require Trsteel/ckeditor-bundle

步骤 2: 启用扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Trsteel\CkeditorBundle\TrsteelCkeditorBundle(),
    );
}

步骤 3: 安装扩展包资源

$ php ./app/console assets:install web --symlink

--symlink 是可选的

步骤 4: 配置扩展包(可选)

要获取完整的配置输出,请使用

$ php ./app/console config:dump-reference TrsteelCkeditorBundle

一个示例配置

trsteel_ckeditor:
    class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
    transformers: ['html_purifier']
    toolbar: ['document', 'clipboard', 'editing', '/', 'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
    toolbar_groups:
        document: ['Source','-','Save','-','Templates']
        clipboard: ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']
        editing: ['Find','Replace','-','SelectAll']
        basicstyles: ['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']
        paragraph: ['NumberedList','BulletedList','-','Outdent','Indent','-','JustifyLeft', 'JustifyCenter','JustifyRight','JustifyBlock']
        links: ['Link','Unlink','Anchor']
        insert: ['Image','Flash','Table','HorizontalRule']
        styles: ['Styles','Format']
        tools: ['Maximize', 'ShowBlocks']
    ui_color: '#000000'
    startup_outline_blocks: true
    width: 800 #Integer or %
    height: 300 #Integer or %
    language: 'en-au'
    filebrowser_upload_url:
        url: relative-url.php?type=file
    filebrowser_image_browse_url:
        route: route_name
        route_parameters:
            type: image

甚至可以完全覆盖您应用程序中的 'document' 工具栏组。

trsteel_ckeditor:
    class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
    toolbar: ['document', 'clipboard', 'editing', '/', 'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
    toolbar_groups:
        document: ['Source']

您可以根据需要创建额外的工具栏组。只需创建一个组并指定项目即可。如上配置所示,'document' 工具栏组已被覆盖,仅显示 'Source' 图标。

步骤 5: 将编辑器添加到表单中

示例表单

<?php

$form = $this->createFormBuilder($post)
            ->add('title', 'text')
            ->add('content', \Trsteel\CkeditorBundle\Form\Type\CkeditorType::class, array(
                'transformers'                 => array('html_purifier'),
                'toolbar'                      => array('document','basicstyles'),
                'toolbar_groups'               => array(
                    'document' => array('Source')
                ),
                'ui_color'                     => '#fff',
                'startup_outline_blocks'       => false,
                'width'                        => '100%',
                'height'                       => '320',
                'language'                     => 'en-au',
                'filebrowser_image_browse_url' => array(
                    'url' => 'relative-url.php?type=file',
                ),
                'filebrowser_image_browse_url' => array(
                    'route'            => 'route_name',
                    'route_parameters' => array(
                        'type' => 'image',
                    ),
                ),
            ))
            ->getForm()
;

注意:config.yml 中的所有参数都可以在表单中重写(除 'class' 外)。

步骤 6: 配置数据转换器

数据转换器将在表单处理时自动更新 HTML 内容。

该扩展包包含一个 html purifier 转换器,归功于 https://github.com/ezyang/htmlpurifier

如果您不希望启用任何转换器,可以通过以下方式禁用它们:

  1. 在配置中全局禁用
trsteel_ckeditor:
    transformers: []
  1. 在特定表单上禁用
<?php

$form = $this->createFormBuilder($post)
            ->add('title', 'text')
            ->add('content', \Trsteel\CkeditorBundle\Form\Type\CkeditorType::class, array(
                'transformers' => array(),
            ))
            ->getForm()
;

下一步