1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2013-2019 2amigOS! Consulting Group LLC |
4
|
|
|
* @link http://2amigos.us |
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
6
|
|
|
*/ |
7
|
|
|
namespace dosamigos\ckeditor; |
8
|
|
|
|
9
|
|
|
use yii\helpers\Html; |
10
|
|
|
use yii\helpers\Json; |
11
|
|
|
use yii\widgets\InputWidget; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* CKEditor renders a CKEditor js plugin for classic editing. |
15
|
|
|
* @see http://docs.ckeditor.com/ |
16
|
|
|
* @author Antonio Ramirez <[email protected]> |
17
|
|
|
* @link http://www.ramirezcobos.com/ |
18
|
|
|
* @link http://www.2amigos.us/ |
19
|
|
|
* @package dosamigos\ckeditor |
20
|
|
|
*/ |
21
|
|
|
class CKEditor extends InputWidget |
22
|
|
|
{ |
23
|
|
|
use CKEditorTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
6 |
|
public function init() |
29
|
|
|
{ |
30
|
6 |
|
parent::init(); |
31
|
6 |
|
$this->initOptions(); |
32
|
6 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
2 |
|
public function run() |
38
|
|
|
{ |
39
|
2 |
|
if ($this->hasModel()) { |
40
|
1 |
|
echo Html::activeTextarea($this->model, $this->attribute, $this->options); |
41
|
1 |
|
} else { |
42
|
1 |
|
echo Html::textarea($this->name, $this->value, $this->options); |
43
|
|
|
} |
44
|
2 |
|
$this->registerPlugin(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Registers CKEditor plugin |
49
|
|
|
* @codeCoverageIgnore |
50
|
|
|
*/ |
51
|
|
|
protected function registerPlugin() |
52
|
|
|
{ |
53
|
|
|
$js = []; |
54
|
|
|
|
55
|
|
|
$view = $this->getView(); |
56
|
|
|
|
57
|
|
|
CKEditorWidgetAsset::register($view); |
58
|
|
|
|
59
|
|
|
$id = $this->options['id']; |
60
|
|
|
|
61
|
|
|
$options = $this->clientOptions !== false && !empty($this->clientOptions) |
62
|
|
|
? Json::encode($this->clientOptions) |
63
|
|
|
: '{}'; |
64
|
|
|
|
65
|
|
|
$js[] = "CKEDITOR.replace('$id', $options);"; |
66
|
|
|
$js[] = "dosamigos.ckEditorWidget.registerOnChangeHandler('$id');"; |
67
|
|
|
|
68
|
|
|
if (isset($this->clientOptions['filebrowserUploadUrl']) || isset($this->clientOptions['filebrowserImageUploadUrl'])) { |
69
|
|
|
$js[] = "dosamigos.ckEditorWidget.registerCsrfImageUploadHandler();"; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$view->registerJs(implode("\n", $js)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|