as-milano/yii2-tinymce

Yii2 extension to use TinyMce with Compressor and FileManager

Installs: 2 099

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Language:JavaScript

Type:yii2-extension

dev-master 2018-05-09 19:17 UTC

This package is auto-updated.

Last update: 2024-05-10 08:14:07 UTC


README

Yii2 extension to simplify TinyMCE WYSIWYG editor usage in your application.

Provides:

  • widget;
  • compressor action;
  • integration with file managers like elFinder;
  • integration with spelling services like Yandex.

Fork of another extension with some additional features:

  • TinyMCE gone to npm package to always have the latest version;
  • Added integration with great elFinder extension;
  • (TODO) Icon to insert many images at once;
  • Few bugs resolved. It's all working now.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist as-milano/yii2-tinymce "*"

or add

"as-milano/yii2-tinymce": "*"

to the require section of your composer.json file.

Usage

Widget basic usage

$form->field($model, 'content')->widget(\milano\tinymce\TinyMce::className())

Scripts compressor

This can be used to optimize widget loading time.

At fist setup controller map:

'controllerMap' => [
    'tinyMce' => [
        'class' => 'milano\tinymce\TinyMceController',
    ]
],

Next add route to configured action to widget options:

$form->field($model, 'content')->widget(\milano\tinymce\TinyMce::className(), [
    'compressorRoute' => 'tinyMce/tinyMceCompressor'
])

ElFinder file manager

Install mihaildev/yii2-elfinder extension. You can just include

"mihaildev/yii2-elfinder": "*"

to the require section of your composer.json file.

Configure elFinder (more info here).:

'controllerMap' => [
    'elfinder' => [
        'class' => 'mihaildev\elfinder\Controller',
        'access' => ['@'],
        'disabledCommands' => ['netmount'],
        'roots' => [
            [
                'baseUrl'=>'@web',
                'basePath'=>'@webroot',
                'path' => 'files/global',
                'name' => 'Global'
            ],
        ],
        'watermark' => [
                'source'         => __DIR__.'/logo.png',
                 'marginRight'    => 5,
                 'marginBottom'   => 5,
                 'quality'        => 95,
                 'transparency'   => 70,
                 'targetType'     => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP,
                 'targetMinPixel' => 200
        ]
    ]
],

Then select file manager provider in the widget:

$form->field($model, 'content')->widget(\milano\tinymce\TinyMce::className(), [
    'fileManager' => [
        'class' => \milano\tinymce\fm\MihaildevElFinder::className()
    ],
])

You can customize some window (width and height) and manager (language, filter, path and multiple) properties. If you want to use different access, watermark and roots setting just prepare controllers:

'controllerMap' => [
    'elf1' => [
        'class' => 'mihaildev\elfinder\Controller',
        'access' => ['@'],
        'roots' => [
            [
                'baseUrl'=>'@web',
                'basePath'=>'@webroot',
                'path' => 'files/global',
                'name' => 'Global'
            ],
        ],
        'watermark' => [
                'source'         => __DIR__.'/logo.png',
                 'marginRight'    => 5,
                 'marginBottom'   => 5,
                 'quality'        => 95,
                 'transparency'   => 70,
                 'targetType'     => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP,
                 'targetMinPixel' => 200
        ]
    ],
    'elf2' => [
        'class' => 'mihaildev\elfinder\Controller',
        'access' => ['*'],
        'roots' => [
            [
                'path' => 'files/some1',
                'name' => ['category' => 'my','message' => 'Some Name']
            ],
            [
                'path'   => 'files/some2',
                'name'   => ['category' => 'my','message' => 'Some Name'],
                'access' => ['read' => '*', 'write' => 'UserFilesAccess']
            ]
        ]
    ]
],

and then point to required controller in the widget:

$form->field($model, 'content2')->widget(\milano\tinymce\TinyMce::className(), [
    'fileManager' => [
        'class' => \milano\tinymce\fm\MihaildevElFinder::className(),
        'controller' => 'elf2'
    ]
])

Any file manager

You can write your own file manager provider. Just inherit it from \milano\tinymce\fm\FileManager class and realize getFileBrowserCallback and registerAsset functions.

Spellchecker

TinyMce has bundled plugin for spellchecking but it requires backed to work.

You can use Yandex spellchecker service.

$form->field($model, 'content')->widget(\milano\tinymce\TinyMce::className(), [
    'spellcheckerUrl' => 'http://speller.yandex.net/services/tinyspell'
])

More info about it here: http://api.yandex.ru/speller/doc/dg/tasks/how-to-spellcheck-tinymce.xml

Or you can build own spellcheking service using code provided by moxicode: http://www.tinymce.com/download/download.php

Combined features

<?= $form->field($model, 'content')->widget(\milano\tinymce\TinyMce::className(), [
    'compressorRoute' => 'site/tinyMceCompressor',
    'fileManager' => [
        'class' => \milano\tinymce\fm\MihaildevElFinder::className()
    ],
    'spellcheckerUrl'=>'http://speller.yandex.net/services/tinyspell',
    'options' => ['rows' => 6]
]) ?>