alexantr/yii2-tinymce

为 Yii 2 定制的 TinyMCE 小部件

安装次数: 18,966

依赖者: 2

建议者: 0

安全: 0

星标: 4

关注者: 1

分支: 1

开放性问题: 3

类型:yii2-extension

1.0.0 2021-08-20 16:36 UTC

This package is auto-updated.

Last update: 2024-09-20 22:58:34 UTC


README

此扩展为 TinyMCE 小部件提供了对 Yii 框架 2.0 的支持。

Latest Stable Version Total Downloads License

安装

通过 composer 安装扩展

composer require alexantr/yii2-tinymce

注意: 默认情况下,将安装最新的 TinyMCE 5。但您可以手动安装 4.x 版本

composer require "tinymce/tinymce:^4.8"

使用方法

在视图文件中的以下代码将渲染一个 TinyMCE 小部件

<?= alexantr\tinymce\TinyMCE::widget(['name' => 'attributeName']) ?>

应使用 clientOptions 属性配置 TinyMCE 选项

<?= alexantr\tinymce\TinyMCE::widget([
    'name' => 'attributeName',
    'clientOptions' => [
        'plugins' => [
            'anchor', 'charmap', 'code', 'help', 'hr',
            'image', 'link', 'lists', 'media', 'paste',
            'searchreplace', 'table',
        ],
        'height' => 500,
        'convert_urls' => false,
        'element_format' => 'html',
        // ...
    ],
]) ?>

如果您想在 ActiveForm 中使用 TinyMCE 小部件,可以这样做

<?= $form->field($model, 'attributeName')->widget(alexantr\tinymce\TinyMCE::className(), [
    'clientOptions' => [
        // ...
    ],
]) ?>

使用预设

为了避免在每个小部件中重复相同的配置,您可以在 @app/config/tinymce.php 中创建预设。小部件的 clientOptions 选项将与此配置合并。

预设示例

<?php
return [
    'plugins' => [
        'anchor', 'charmap', 'code', 'help', 'hr',
        'image', 'link', 'lists', 'media', 'paste',
        'searchreplace', 'table',
    ],
    'height' => 500,
    'convert_urls' => false,
    'element_format' => 'html',
    'image_caption' => true,
    'keep_styles' => false,
    'paste_block_drop' => true,
    'table_default_attributes' => new yii\web\JsExpression('{}'),
    'table_default_styles' => new yii\web\JsExpression('{}'),
    'invalid_elements' => 'acronym,font,center,nobr,strike,noembed,script,noscript',
    'extended_valid_elements' => 'strong/b,em/i,table[style]',
    // elFinder file manager https://github.com/alexantr/yii2-elfinder
    'file_picker_callback' => alexantr\elfinder\TinyMCE::getFilePickerCallback(['elfinder/tinymce']),
];

您可以使用 presetPath 属性更改默认路径

<?= alexantr\tinymce\TinyMCE::widget([
    'name' => 'attributeName',
    'presetPath' => '@backend/config/my-tinymce-config.php',
    'clientOptions' => [
        'height' => 1000,
    ],
]) ?>