|
| 1 | +# Editor.js Widget for Yii 2 |
| 2 | + |
| 3 | +`Editor.js Widget` is a wrapper for [Editor.js](https://github.com/codex-team/editor.js), next generation block styled editor. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +The preferred way to install this extension is through [composer](http://getcomposer.org/download/). |
| 8 | + |
| 9 | +Either run |
| 10 | + |
| 11 | +```bash |
| 12 | +$ php composer.phar require --prefer-dist zakurdaev/yii2-editorjs-widget "*" |
| 13 | +``` |
| 14 | + |
| 15 | +or add |
| 16 | + |
| 17 | +```json |
| 18 | +"zakurdaev/yii2-editorjs-widget": "*" |
| 19 | +``` |
| 20 | + |
| 21 | +to the `require` section of your `composer.json` file. |
| 22 | + |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Once the extension is installed, simply use it in your code: |
| 27 | + |
| 28 | +### Like a widget |
| 29 | + |
| 30 | +```php |
| 31 | +echo \zakurdaev\editorjs\EditorJsWidget::widget([ |
| 32 | + 'selector' => 'redactor' |
| 33 | +]); |
| 34 | +``` |
| 35 | + |
| 36 | +### Like an ActiveForm widget |
| 37 | + |
| 38 | +```php |
| 39 | +use \zakurdaev\editorjs\EditorJsWidget; |
| 40 | + |
| 41 | +echo $form->field($model, 'content_json')->widget(EditorJsWidget::class, [ |
| 42 | + 'selectorForm' => $form->id |
| 43 | +])->label(); |
| 44 | +``` |
| 45 | +### Supported block |
| 46 | +The plugin is able to support all blocks for Editor.js. You can use the standard Asset or use Asset CDN or write your own. |
| 47 | + |
| 48 | +#### EditorJsAsset |
| 49 | +Include: |
| 50 | +* editorjs/header v2.4.1 |
| 51 | +* editorjs/paragraph v2.6.1 |
| 52 | +* editorjs/image v2.3.4 |
| 53 | +* editorjs/list v1.4.0 |
| 54 | +* editorjs/table v1.2.2 |
| 55 | +* editorjs/quote v2.3.0 |
| 56 | +* editorjs/warning v1.1.1 |
| 57 | +* editorjs/code v2.4.1 |
| 58 | +* editorjs/embed v2.3.1 |
| 59 | +* editorjs/delimiter v1.1.0 |
| 60 | +* editorjs/inline-code v1.3.1 |
| 61 | + |
| 62 | +#### Custom Asset |
| 63 | +```php |
| 64 | +use \zakurdaev\editorjs\EditorJsWidget; |
| 65 | + |
| 66 | +echo $form->field($model, 'content_json')->widget(EditorJsWidget::class, [ |
| 67 | + 'selectorForm' => $form->id, |
| 68 | + 'assetClass' => 'YOUR/PATH/TO/ASSET' |
| 69 | +])->label(); |
| 70 | +``` |
| 71 | + |
| 72 | + |
| 73 | +### Upload image by file and url |
| 74 | + |
| 75 | +Widget supports image loading for [Editor.js Image Block](https://github.com/editor-js/image). |
| 76 | + |
| 77 | +```php |
| 78 | +// SiteController.php |
| 79 | +public function actions() |
| 80 | +{ |
| 81 | + return [ |
| 82 | + 'upload-file' => [ |
| 83 | + 'class' => UploadImageAction::class, |
| 84 | + 'mode' => UploadImageAction::MODE_FILE, |
| 85 | + 'url' => 'https://example.com/upload_dir/', |
| 86 | + 'path' => '@app/web/upload_dir', |
| 87 | + 'validatorOptions' => [ |
| 88 | + 'maxWidth' => 1000, |
| 89 | + 'maxHeight' => 1000 |
| 90 | + ] |
| 91 | + ], |
| 92 | + 'fetch-url' => [ |
| 93 | + 'class' => UploadImageAction::class, |
| 94 | + 'mode' => UploadImageAction::MODE_URL, |
| 95 | + 'url' => 'https://example.com/upload_dir/', |
| 96 | + 'path' => '@app/web/upload_dir' |
| 97 | + ] |
| 98 | + ]; |
| 99 | +} |
| 100 | + |
| 101 | +// view.php |
| 102 | +echo \zakurdaev\editorjs\EditorJsWidget::widget([ |
| 103 | + 'selector' => 'redactor', |
| 104 | + 'endpoints' => [ |
| 105 | + 'uploadImageByFile' => Url::to(['/site/upload-file']), |
| 106 | + 'uploadImageByUrl' => Url::to(['/site/fetch-url']), |
| 107 | + ], |
| 108 | +]); |
| 109 | +``` |
| 110 | + |
| 111 | +## License |
| 112 | +The BSD License (BSD).Please see [License File](LICENSE.md) for more information. |
0 commit comments