short-edition / tinymce-bundle
此Bundle将TinyMCE WYSIWYG编辑器集成到Symfony2项目中。
Requires
- php: ^8.0
- symfony/framework-bundle: ^5.0
- twig/twig: ^2.12|^3.0
- dev-bugfix
- 3.x-dev
- dev-master / 3.x-dev
- v3.0.2
- v3.0.1
- v3.0.0
- 2.x-dev
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1
- v2.0
- 1.x-dev
- v1.1.1
- v1.1
- v1.0.1
- v1.0
- v0.4.0
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.0
- dev-bugfix-v6
- dev-bugfix-2
- dev-paste_word_valid_elements-option
- dev-feature-file-picker-callback
This package is auto-updated.
Last update: 2022-07-25 10:29:17 UTC
README
📦 此Bundle使得将TinyMCE WYSIWYG编辑器添加到您的Symfony2项目中变得非常简单。
安装
选择合适的版本
Bundle版本 (X.Y) | PHP | Symfony | 注释 |
---|---|---|---|
3.0 | >= 7.2 | >= 5.0 | 实际版本 |
2.4 | >= 7.1 | >= 3.4 和 4.* | |
2.0 | >= 5.4 | >= 3.0 | |
1.0 | >= 5.4 | >= 2.1 和 <= 2.8 |
注意!要升级您的配置,请阅读 UPGRADE.md
通过Composer将TinyMCE bundle添加为应用程序的依赖项
$ php composer.phar require stfalcon/tinymce-bundle='X.Y'
将StfalconTinymceBundle添加到您的应用程序内核中。
// app/AppKernel.php <?php // ... public function registerBundles() { $bundles = array( // ... new Stfalcon\Bundle\TinymceBundle\StfalconTinymceBundle(), ); }
此Bundle需要将必要的资源复制到web文件夹中。您可以使用以下命令
$ php app/console assets:install web/
包含在模板中
此Bundle包含一个用于Twig的扩展。这使得将TinyMCE JavaScript包含到您的页面中变得非常简单。将以下标签添加到您想要使用TinyMCE的地方。它将输出完整的JavaScript,包括<script>
标签。将其添加到页面底部以优化性能。
{{ tinymce_init() }}
您也可以通过传递类似下面的选项来覆盖默认配置
{{ tinymce_init({'use_callback_tinymce_init': true, 'theme': {'simple': {'menubar': false}}}) }}
或者
{{ tinymce_init({
theme: {'simple':{'language': app.request.locale, 'height': 500 }},
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
autosave_ask_before_unload: false,
asset_package_name: 'backend'})
}}
新增! 添加指定资产包文档以生成正确的js链接,见上面,参数: asset_package_name
基本配置
默认情况下,tinymce对所有页面的文本区域都启用。如果您想自定义它,请按照以下步骤操作
将“tinymce”类添加到textarea字段中以初始化TinyMCE。
<textarea class="tinymce"></textarea>
如果您想使用编辑器的jQuery版本,请设置以下参数
stfalcon_tinymce: include_jquery: true tinymce_jquery: true ...
选项include_jquery
允许您从Google CDN加载外部jQuery库。如果您没有在页面上包含jQuery,将其设置为true
。
如果您正在使用FormBuilder,请使用数组添加类。您还可以使用theme
选项将使用的主题更改为除'simple'之外的主题(即您的配置中定义的其他主题之一 - 上述示例定义了'bbcode')。例如。
<?php $builder->add('introtext', 'textarea', array( 'attr' => array( 'class' => 'tinymce', 'data-theme' => 'bbcode' // Skip it if you want to use default theme ) ));
本地化
您可以通过在配置的最高级别添加语言选择器来更改TinyMCE编辑器的语言,例如:
// app/config/config.yml stfalcon_tinymce: include_jquery: true tinymce_jquery: true selector: ".tinymce" language: %locale% theme: simple: theme: "modern" ...
注意!由于无法为每个编辑实例设置自定义语言,此选项将设置所有实例的语言。
在示例中,我们通过参数.ini设置默认语言。当然,您可以通过传递语言代码(如ru
或ru_RU
、en
或en_US
)来设置默认语言。
如果未设置语言参数,则默认语言将从会话中获取。
多重选择器
您可以指定一个或多个选择器用于编辑器的位置。
// app/config/config.yml stfalcon_tinymce: selector: ".tinymce"
或者
// app/config/config.yml stfalcon_tinymce: selector: - ".tinymce" - "#tinymce"
或者
// app/config/config.yml stfalcon_tinymce: selector: [".tinymce", "#tinymce"]
自定义配置
根据TinyMCE文档,您可以按自己的意愿配置编辑器。下面是您可以自行配置的几乎所有参数的列表。
// app/config/config.yml stfalcon_tinymce: include_jquery: true tinymce_jquery: true selector: - ".tinymce" - "#editor1" - "#editor2" base_url: "http://yourdomain.com/" # this parameter may be included if you need to override the assets_base_urls for your template engine (to override a CDN base url) # Get current language from the parameters.ini language: %locale% # Custom buttons tinymce_buttons: stfalcon: # Id of the first button title: "Stfalcon" image: "http://stfalcon.com/favicon.ico" theme: # Simple theme: same as default theme simple: ~ # Advanced theme with almost all enabled plugins advanced: plugins: - "advlist autolink lists link image charmap print preview hr anchor pagebreak" - "searchreplace wordcount visualblocks visualchars code fullscreen" - "insertdatetime media nonbreaking save table contextmenu directionality" - "emoticons template paste textcolor" toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" toolbar2: "print preview media | forecolor backcolor emoticons | stfalcon | example" image_advtab: true templates: - {title: 'Test template 1', content: 'Test 1'} - {title: 'Test template 2', content: 'Test 2'} # BBCode tag compatible theme (see http://www.bbcode.org/reference.php) bbcode: plugins: ["bbcode, code, link, preview"] menubar: false toolbar1: "bold,italic,underline,undo,redo,link,unlink,removeformat,cleanup,code,preview"
外部插件支持
如果您想加载一些位于您捆绑包中的外部插件,您应按照示例进行配置。
stfalcon_tinymce: external_plugins: filemanager: url: "asset[bundles/acmedemo/js/tinymce-plugin/filemanager/editor_plugin.js]" imagemanager: url: "asset[bundles/acmedemo/js/tinymce-plugin/imagemanager/editor_plugin.js]" ... theme: simple: theme: "modern" ...
自定义按钮
您可以向编辑器的工具栏添加一些自定义按钮(参见:http://www.tinymce.com/tryit/button.php,http://www.tinymce.com/wiki.php/api4:method.tinymce.Editor.addButton)
首先,您应在您的配置中描述它。
stfalcon_tinymce: tinymce_buttons: stfalcon: # Id of the first button title: "Stfalcon" image: "http://stfalcon.com/favicon.ico" hello_world: # Id of the second button title: "Google" image: "http://google.com/favicon.ico" ... or for the local images ... image: "asset[bundles/somebundle/images/icon.ico]" theme: simple: ... toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" toolbar2: "print preview media | forecolor backcolor emoticons | stfalcon | hello_world"
然后,您应该为按钮创建基于其按钮ID的回调函数tinymce_button_
。
function tinymce_button_stfalcon(ed) { ed.focus(); ed.selection.setContent("Hello from stfalcon.com :)"); } function tinymce_button_hello_world(ed) { ed.focus(); ed.selection.setContent("Hello world!"); }
自定义CSS
此选项允许您指定一个自定义CSS文件,该文件扩展了主题内容CSS。此CSS文件是编辑器中使用的CSS(可编辑区域)。此选项也可以是逗号分隔的URL列表。
如果您指定了相对路径,则它相对于包含TinyMCE的(HTML)文件的URL解析,而不是相对于TinyMCE本身。
stfalcon_tinymce: ... theme: simple: content_css: "asset[bundles/mybundle/css/tinymce-content.css]" ...
注意!请参阅官方TinyMCE文档以获取更多详细信息:http://www.tinymce.com/wiki.php/Configuration:content_css
初始化事件
就像jQuery中的$(document).ready()一样,您也可以在TinyMCE中监听初始化事件。
为此,您必须编辑您的配置并将use_callback_tinymce_init
设置为true。
app/config/config.yml
:
stfalcon_tinymce: ... use_callback_tinymce_init: true ...
然后创建一个名为callback_tinymce_init
的javascript回调函数,如下所示:
function callback_tinymce_init(editor) { // execute your best script ever }
如何初始化动态加载元素的TinyMCE
要为新的加载文本区域初始化TinyMCE,只需调用initTinyMCE()
函数即可。
Sonata Admin Bundle示例
jQuery(document).ready(function() { $('form').on('sonata.add_element', function(){ initTinyMCE(); }); });