1 | <?php |
||
18 | class JsonEditor extends InputWidget |
||
19 | { |
||
20 | /** |
||
21 | * @var array options which will be passed to JSON editor |
||
22 | * @see https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options |
||
23 | */ |
||
24 | public $clientOptions = []; |
||
25 | |||
26 | /** |
||
27 | * @var string[] list of JSON editor modes for which all fields should be collapsed automatically; |
||
28 | * allowed modes 'tree', 'view', and 'form' |
||
29 | * @see https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#jsoneditorcollapseall |
||
30 | */ |
||
31 | public $collapseAll = []; |
||
32 | |||
33 | /** |
||
34 | * @var array HTML attributes to be applied to the JSON editor container tag |
||
35 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered |
||
36 | */ |
||
37 | public $containerOptions = []; |
||
38 | |||
39 | /** |
||
40 | * @var mixed this property can be used instead of `value`; |
||
41 | * while `value` must be JSON string, `decodedValue` accepts decoded JSON, i.e. arrays, floats, booleans etc.; |
||
42 | * `decodedValue` has precedence over `value`: if `decodedValue` is set then `value` will be ignored |
||
43 | * @see value |
||
44 | */ |
||
45 | public $decodedValue; |
||
46 | |||
47 | /** |
||
48 | * @var string default value |
||
49 | */ |
||
50 | public $defaultValue = '{}'; |
||
51 | |||
52 | /** |
||
53 | * @var string[] list of JSON editor modes for which all fields should be expanded automatically; |
||
54 | * allowed modes 'tree', 'view', and 'form' |
||
55 | * @see https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#jsoneditorexpandall |
||
56 | */ |
||
57 | public $expandAll = []; |
||
58 | |||
59 | /** |
||
60 | * @var null|bool whether to use minimalist version of JSON editor; |
||
61 | * note that "minimalist" is not the same as "minimized"; |
||
62 | * if property is not set then extension will try to determine automatically whether full version is needed, |
||
63 | * if full version is not required then minimalist version will be used; |
||
64 | * you can explicitly set this property to true or false if automatic detection does not fit for you application |
||
65 | * @see https://github.com/josdejong/jsoneditor/blob/master/src/docs/which%20files%20do%20I%20need.md |
||
66 | */ |
||
67 | public $minimalist; |
||
68 | |||
69 | /** |
||
70 | * @var string[] list of client options which should be automatically converted to `JsExpression` |
||
71 | * @see clientOptions |
||
72 | */ |
||
73 | protected $jsExpressionClientOptions = [ |
||
74 | 'ace', |
||
75 | 'ajv', |
||
76 | 'onChange', |
||
77 | 'onChangeJSON', |
||
78 | 'onChangeText', |
||
79 | 'onClassName', |
||
80 | 'onEditable', |
||
81 | 'onError', |
||
82 | 'onModeChange', |
||
83 | 'onNodeName', |
||
84 | 'onValidate', |
||
85 | 'onCreateMenu', |
||
86 | 'schema', |
||
87 | 'schemaRefs', |
||
88 | 'templates', |
||
89 | 'autocomplete', |
||
90 | 'onTextSelectionChange', |
||
91 | 'onSelectionChange', |
||
92 | 'onEvent', |
||
93 | 'onColorPicker', |
||
94 | 'languages', |
||
95 | 'modalAnchor', |
||
96 | ]; |
||
97 | |||
98 | /** |
||
99 | * @var string default JSON editor mode |
||
100 | */ |
||
101 | private $mode = 'tree'; |
||
102 | |||
103 | /** |
||
104 | * @var string[] available JSON editor modes |
||
105 | */ |
||
106 | private $modes = []; |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 15 | public function init() |
|
131 | |||
132 | /** |
||
133 | * Analyses input data and determines what should be used as value. |
||
134 | * This method must set `value` and `decodedValue` properties. |
||
135 | */ |
||
136 | 15 | protected function determineValue() |
|
162 | |||
163 | /** |
||
164 | * Check whether `value` property is set. For JSON string the empty string is considered as equivalent of null. |
||
165 | * @return bool whether `value` property is set. |
||
166 | */ |
||
167 | 14 | protected function issetValue() |
|
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | 15 | public function run() |
|
186 | |||
187 | /** |
||
188 | * Initializes client options. |
||
189 | */ |
||
190 | 15 | protected function initClientOptions() |
|
200 | |||
201 | /** |
||
202 | * Registers the needed client script. |
||
203 | */ |
||
204 | 15 | public function registerClientScript() |
|
260 | } |
||
261 |