Skip to content

Commit

Permalink
Replace Zend_Json in the editor form element
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanners committed May 24, 2017
1 parent 62c566d commit b379aea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Editablemultiselect extends \Magento\Framework\Data\Form\Element\Multisele
* @param Escaper $escaper
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Factory $factoryElement,
Expand All @@ -53,6 +54,7 @@ public function __construct(
* Retrieve HTML markup of the element
*
* @return string
* @throws \InvalidArgumentException
*/
public function getElementHtml()
{
Expand Down
21 changes: 17 additions & 4 deletions lib/internal/Magento/Framework/Data/Form/Element/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@
class Editor extends Textarea
{
/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* Editor constructor.
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
$data = []
$data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);

Expand All @@ -36,6 +45,9 @@ public function __construct(
$this->setType('textarea');
$this->setExtType('textarea');
}

$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
Expand All @@ -55,6 +67,7 @@ protected function getButtonTranslations()
/**
* @return string
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @throws \InvalidArgumentException
*/
public function getElementHtml()
{
Expand Down Expand Up @@ -141,7 +154,7 @@ public function getElementHtml()
' = new tinyMceWysiwygSetup("' .
$this->getHtmlId() .
'", ' .
\Zend_Json::encode(
$this->serializer->serialize(
$this->getConfig()
) .
');' .
Expand Down Expand Up @@ -180,7 +193,7 @@ public function getElementHtml()
//<![CDATA[
require(["jquery", "mage/translate", "mage/adminhtml/wysiwyg/widget"], function(jQuery){
(function($) {
$.mage.translate.add(' . \Zend_Json::encode($this->getButtonTranslations()) . ')
$.mage.translate.add(' . $this->serializer->serialize($this->getButtonTranslations()) . ')
})(jQuery);
});
//]]>
Expand Down Expand Up @@ -425,7 +438,7 @@ public function getConfig($key = null)
* Translate string using defined helper
*
* @param string $string String to be translated
* @return \Magento\Framework\Phrase
* @return string
*/
public function translate($string)
{
Expand Down

0 comments on commit b379aea

Please sign in to comment.