Redactor Widget

What is Imperavi Widget?

Imperavi Redactor Widget is a wrapper for Imperavi Redactor, a high quality WYSIWYG editor.

Important

Note that Imperavi Redactor itself is a proprietary commercial copyrighted software but since Yii community bought OEM license you can use it for free with Yii.

Installation

The preferred way to install this extension is through composer.

Either run

composer require vova07/yii2-imperavi-widget:~1.2

or add the following to the require section of your application's composer.json file:

"vova07/yii2-imperavi-widget" : "~1.2" 

Usage example

Once the extension is installed, simply use it in your code:

As a Widget

use vova07\imperavi\Widget as Redactor;

echo Redactor::widget([
    'name' => 'redactor',
    'settings' => [
        'lang' => 'ru',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen'
        ]
    ]
]);

Like an ActiveForm Widget

use vova07\imperavi\Widget as Redactor;

echo $form->field($model, 'content')->widget(Redactor::className(), [
    'settings' => [
        'lang' => 'ru',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen'
        ]
    ]
]);

Like a Widget for a Predefined Textarea

echo \vova07\imperavi\Widget::widget([
    'selector' => '#my-textarea-id',
    'settings' => [
        'lang' => 'ru',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen'
        ]
    ]
]);

Upload Images

// DefaultController.php
public function actions()
{
    return [
        'image-upload' => [
            'class' => 'vova07\imperavi\actions\UploadAction',
            // Directory URL address, where files are stored.
            'url' => 'http://my-site.com/images/', 
            // Or absolute path to directory where files are stored.
            'path' => '@alias/to/my/path' 
        ],
    ];
}

// View.php
echo \vova07\imperavi\Widget::widget([
    'selector' => '#my-textarea-id',
    'settings' => [
        'lang' => 'ru',
        'minHeight' => 200,
        'imageUpload' => Url::to(['/default/image-upload'])
    ]
]);

Adding Custom Plugins

echo \vova07\imperavi\Widget::widget([
    'selector' => '#my-textarea-id',
    'settings' => [
        'lang' => 'ru',
        'minHeight' => 200,
        'plugins' => [
            'clips',
            'fullscreen'
        ]
    ],
    'plugins' => [
        'my-custom-plugin' => 'app\assets\MyPluginBundle'
    ]
]);

Share this

Contributors Thanks All

 

Do you have a good idea? Why Don't We Talk?