trsteel / ckeditor-bundle
Symfony 扩展包,用于轻松集成 CKEditor WYSIWYG 编辑器
1.21.1
2024-02-09 01:10 UTC
Requires
- php: >=8.1
- ezyang/htmlpurifier: ~4.0
- symfony/form: ^6.0 || ^7.0
- symfony/framework-bundle: ^6.0 || ^7.0
- twig/twig: >=1.1,<4.0
Requires (Dev)
- php-cs-fixer/shim: ^3.13
- phpstan/phpstan: ^1.9
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^9.0
- rector/rector: ^0.15.10
- symfony/asset: ^6.0 || ^7.0
- symfony/phpunit-bridge: ^6.0 || ^7.0
- symfony/templating: ^6.0 || ^7.0
- symfony/twig-bundle: ^6.0 || ^7.0
- symfony/yaml: ^6.0 || ^7.0
- 1.21.1
- 1.21.0
- 1.20.0
- 1.19.0
- 1.18.0
- v1.17.0
- v1.16.0
- v1.15.4
- v1.15.3
- v1.15.2
- v1.15.0
- v1.14.0
- v1.13.1
- v1.13.0
- v1.12.1
- 1.12.0
- dev-master / 1.11.x-dev
- v1.11.0
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.0
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1
- v1.0
This package is auto-updated.
Last update: 2024-09-09 02:42:37 UTC
README
- 将 TrsteelCkeditorBundle 添加到您的 composer.json 文件中
- 启用该扩展包
- 安装扩展包资源
- 配置扩展包(可选)
- 将编辑器添加到表单中
- 配置数据转换器
步骤 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
如果您不希望启用任何转换器,可以通过以下方式禁用它们:
- 在配置中全局禁用
trsteel_ckeditor: transformers: []
- 在特定表单上禁用
<?php $form = $this->createFormBuilder($post) ->add('title', 'text') ->add('content', \Trsteel\CkeditorBundle\Form\Type\CkeditorType::class, array( 'transformers' => array(), )) ->getForm() ;