Skip to content

Commit

Permalink
Fix issue with config not serializing as it is a multi level object
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanners committed May 24, 2017
1 parent b379aea commit abb39b4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/internal/Magento/Framework/Data/Form/Element/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()
{
Expand Down Expand Up @@ -145,7 +158,7 @@ public function getElementHtml()
], function(jQuery){' .
"\n" .
' (function($) {$.mage.translate.add(' .
\Zend_Json::encode(
$this->serializer->serialize(
$this->getButtonTranslations()
) .
')})(jQuery);' .
Expand All @@ -154,9 +167,7 @@ public function getElementHtml()
' = new tinyMceWysiwygSetup("' .
$this->getHtmlId() .
'", ' .
$this->serializer->serialize(
$this->getConfig()
) .
$this->getJsonConfig() .
');' .
$forceLoad .
'
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit abb39b4

Please sign in to comment.