Skip to content

Commit

Permalink
MAGETWO-69369: Explace the direct usage of Zend_Json with a call to t…
Browse files Browse the repository at this point in the history
…he Json Help class #9344
  • Loading branch information
ishakhsuvarov authored May 31, 2017
2 parents 7512794 + ef545ac commit 657b5ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Main;

use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;
use Magento\Backend\Block\Template;

/**
* Widget Instance page groups (predefined layouts group) to display on
*
* @method \Magento\Widget\Model\Widget\Instance getWidgetInstance()
*/
class Layout extends \Magento\Backend\Block\Template implements \Magento\Framework\Data\Form\Element\Renderer\RendererInterface
class Layout extends Template implements RendererInterface
{
/**
* @var AbstractElement|null
Expand All @@ -32,17 +34,25 @@ class Layout extends \Magento\Backend\Block\Template implements \Magento\Framewo
*/
protected $_productType;

/**
* @var Json
*/
private $serializer;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Catalog\Model\Product\Type $productType
* @param array $data
* @param Json|null $serializer
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Catalog\Model\Product\Type $productType,
array $data = []
array $data = [],
Json $serializer = null
) {
$this->_productType = $productType;
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -242,7 +252,7 @@ public function getDisplayOnContainers()
public function getLayoutsChooser()
{
$chooserBlock = $this->getLayout()->createBlock(
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Layout::class
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Layout::class
)->setName(
'widget_instance[<%- data.id %>][pages][layout_handle]'
)->setId(
Expand All @@ -268,7 +278,7 @@ public function getLayoutsChooser()
public function getPageLayoutsPageChooser()
{
$chooserBlock = $this->getLayout()->createBlock(
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\DesignAbstraction::class
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\DesignAbstraction::class
)->setName(
'widget_instance[<%- data.id %>][page_layouts][layout_handle]'
)->setId(
Expand Down Expand Up @@ -335,17 +345,26 @@ public function getPageGroups()
$pageGroups = [];
if ($widgetInstance->getPageGroups()) {
foreach ($widgetInstance->getPageGroups() as $pageGroup) {
$pageGroups[] = [
'page_id' => $pageGroup['page_id'],
'group' => $pageGroup['page_group'],
'block' => $pageGroup['block_reference'],
'for_value' => $pageGroup['page_for'],
'layout_handle' => $pageGroup['layout_handle'],
$pageGroup['page_group'] . '_entities' => $pageGroup['entities'],
'template' => $pageGroup['page_template'],
];
$pageGroups[] = $this->serializer->serialize($this->getPageGroup($pageGroup));
}
}
return $pageGroups;
}

/**
* @param array $pageGroup
* @return array
*/
private function getPageGroup(array $pageGroup)
{
return [
'page_id' => $pageGroup['page_id'],
'group' => $pageGroup['page_group'],
'block' => $pageGroup['block_reference'],
'for_value' => $pageGroup['page_for'],
'layout_handle' => $pageGroup['layout_handle'],
$pageGroup['page_group'] . '_entities' => $pageGroup['entities'],
'template' => $pageGroup['page_template'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ window.WidgetInstance = WidgetInstance;

jQuery(function(){
<?php foreach ($block->getPageGroups() as $pageGroup): ?>
WidgetInstance.addPageGroup(<?php /* @noEscape */ echo Zend_Json::encode($pageGroup) ?>);
WidgetInstance.addPageGroup(<?php /* @noEscape */ echo $pageGroup ?>);
<?php endforeach; ?>
Event.observe(document, 'product:changed', function(event){
WidgetInstance.checkProduct(event);
Expand Down

0 comments on commit 657b5ad

Please sign in to comment.