A
A
Alexander Izmailov2016-10-11 18:56:05
Yii
Alexander Izmailov, 2016-10-11 18:56:05

How to add custom plugin for yii2 tinymce?

I installed this widget in yii2, but I don’t understand how to write my plugin and add it, I just need a button that, when pressed, adds static text.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-12
@pocifis

1. Take a ready-made plugin for Yii2 and install it into the system, because doing something from scratch is a bicycle invention
2. Inherit the installed plugin at the class level (roughly speaking, this will be your modification)
3. In your plugin modification, set for JS -plugin to the setup property (during initialization):

setup: function (editor) {
    editor.addButton('mybutton', {
      text: 'My button',
      icon: <url-to-icon>,
      onclick: function () {
        editor.insertContent('&nbsp;<b>It\'s my content!</b>&nbsp;');
      }
    });
  },

For example, for this ready-made widget, the last item can be implemented like this:
use dosamigos\tinymce\TinyMce;
 

<?= $form->field($model, 'text')->widget(TinyMce::className(), [
    'options' => ['rows' => 6],
    'language' => 'es',
    'clientOptions' => [
        'plugins' => [
            "advlist autolink lists link charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste"
        ],
        'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        'setup' => // тут JS код указанный в пункте 3
    ]
]);?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question