From abb39b484876c3bb187ef2038098d3efa432b2f8 Mon Sep 17 00:00:00 2001 From: dmanners Date: Wed, 24 May 2017 16:39:28 +0000 Subject: [PATCH] Fix issue with config not serializing as it is a multi level object --- .../Framework/Data/Form/Element/Editor.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php index bd89fe400035f..6ed2d8293e61d 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php @@ -45,7 +45,6 @@ public function __construct( $this->setType('textarea'); $this->setExtType('textarea'); } - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Serialize\Serializer\Json::class); } @@ -64,10 +63,24 @@ protected function getButtonTranslations() return $buttonTranslations; } + /** + * @return bool|string + * @throws \InvalidArgumentException + */ + private function getJsonConfig() + { + if (is_object($this->getConfig()) && method_exists($this->getConfig(), 'toJson')) { + return $this->getConfig()->toJson(); + } else { + return $this->serializer->serialize( + $this->getConfig() + ); + } + } + /** * @return string * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * @throws \InvalidArgumentException */ public function getElementHtml() { @@ -145,7 +158,7 @@ public function getElementHtml() ], function(jQuery){' . "\n" . ' (function($) {$.mage.translate.add(' . - \Zend_Json::encode( + $this->serializer->serialize( $this->getButtonTranslations() ) . ')})(jQuery);' . @@ -154,9 +167,7 @@ public function getElementHtml() ' = new tinyMceWysiwygSetup("' . $this->getHtmlId() . '", ' . - $this->serializer->serialize( - $this->getConfig() - ) . + $this->getJsonConfig() . ');' . $forceLoad . ' @@ -438,7 +449,7 @@ public function getConfig($key = null) * Translate string using defined helper * * @param string $string String to be translated - * @return string + * @return \Magento\Framework\Phrase */ public function translate($string) {