meniam/ckeditor-bundle

CKEditor WYSIWYG的简单集成Symfony2包

安装次数: 3,975

依赖者: 0

建议者: 0

安全性: 0

星标: 1

关注者: 2

分支: 59

类型:symfony-bundle

v1.9.2 2019-01-28 13:19 UTC

README

Build Status

KnpBundles Badge

安装

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

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

php composer.phar require Trsteel/ckeditor-bundle ~1.8

步骤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', 'ckeditor', 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内容。

由于ezyang/htmlpurifier的帮助,该包包含一个HTML净化器转换器https://github.com/ezyang/htmlpurifier

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

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

$form = $this->createFormBuilder($post)
            ->add('title', 'text')
            ->add('content', 'ckeditor', array(
                'transformers' => array(),
            ))
            ->getForm()
;

下一步