16
16
class Editor extends Textarea
17
17
{
18
18
/**
19
+ * @var \Magento\Framework\Serialize\Serializer\Json
20
+ */
21
+ private $ serializer ;
22
+
23
+ /**
24
+ * Editor constructor.
19
25
* @param Factory $factoryElement
20
26
* @param CollectionFactory $factoryCollection
21
27
* @param Escaper $escaper
22
28
* @param array $data
29
+ * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
30
+ * @throws \RuntimeException
23
31
*/
24
32
public function __construct (
25
33
Factory $ factoryElement ,
26
34
CollectionFactory $ factoryCollection ,
27
35
Escaper $ escaper ,
28
- $ data = []
36
+ $ data = [],
37
+ \Magento \Framework \Serialize \Serializer \Json $ serializer = null
29
38
) {
30
39
parent ::__construct ($ factoryElement , $ factoryCollection , $ escaper , $ data );
31
40
@@ -36,6 +45,8 @@ public function __construct(
36
45
$ this ->setType ('textarea ' );
37
46
$ this ->setExtType ('textarea ' );
38
47
}
48
+ $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()
49
+ ->get (\Magento \Framework \Serialize \Serializer \Json::class);
39
50
}
40
51
41
52
/**
@@ -52,6 +63,21 @@ protected function getButtonTranslations()
52
63
return $ buttonTranslations ;
53
64
}
54
65
66
+ /**
67
+ * @return bool|string
68
+ * @throws \InvalidArgumentException
69
+ */
70
+ private function getJsonConfig ()
71
+ {
72
+ if (is_object ($ this ->getConfig ()) && method_exists ($ this ->getConfig (), 'toJson ' )) {
73
+ return $ this ->getConfig ()->toJson ();
74
+ } else {
75
+ return $ this ->serializer ->serialize (
76
+ $ this ->getConfig ()
77
+ );
78
+ }
79
+ }
80
+
55
81
/**
56
82
* @return string
57
83
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -132,7 +158,7 @@ public function getElementHtml()
132
158
], function(jQuery){ ' .
133
159
"\n" .
134
160
' (function($) {$.mage.translate.add( ' .
135
- \Zend_Json:: encode (
161
+ $ this -> serializer -> serialize (
136
162
$ this ->getButtonTranslations ()
137
163
) .
138
164
')})(jQuery); ' .
@@ -141,9 +167,7 @@ public function getElementHtml()
141
167
' = new tinyMceWysiwygSetup(" ' .
142
168
$ this ->getHtmlId () .
143
169
'", ' .
144
- \Zend_Json::encode (
145
- $ this ->getConfig ()
146
- ) .
170
+ $ this ->getJsonConfig () .
147
171
'); ' .
148
172
$ forceLoad .
149
173
'
@@ -180,7 +204,7 @@ public function getElementHtml()
180
204
//<![CDATA[
181
205
require(["jquery", "mage/translate", "mage/adminhtml/wysiwyg/widget"], function(jQuery){
182
206
(function($) {
183
- $.mage.translate.add( ' . \Zend_Json:: encode ($ this ->getButtonTranslations ()) . ')
207
+ $.mage.translate.add( ' . $ this -> serializer -> serialize ($ this ->getButtonTranslations ()) . ')
184
208
})(jQuery);
185
209
});
186
210
//]]>
0 commit comments