Skip to content

Commit 657b5ad

Browse files
MAGETWO-69369: Explace the direct usage of Zend_Json with a call to the Json Help class #9344
2 parents 7512794 + ef545ac commit 657b5ad

File tree

2 files changed

+35
-16
lines changed
  • app/code/Magento/Widget

2 files changed

+35
-16
lines changed

app/code/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/Layout.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Main;
108

119
use Magento\Framework\Data\Form\Element\AbstractElement;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Serialize\Serializer\Json;
12+
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;
13+
use Magento\Backend\Block\Template;
1214

1315
/**
1416
* Widget Instance page groups (predefined layouts group) to display on
1517
*
1618
* @method \Magento\Widget\Model\Widget\Instance getWidgetInstance()
1719
*/
18-
class Layout extends \Magento\Backend\Block\Template implements \Magento\Framework\Data\Form\Element\Renderer\RendererInterface
20+
class Layout extends Template implements RendererInterface
1921
{
2022
/**
2123
* @var AbstractElement|null
@@ -32,17 +34,25 @@ class Layout extends \Magento\Backend\Block\Template implements \Magento\Framewo
3234
*/
3335
protected $_productType;
3436

37+
/**
38+
* @var Json
39+
*/
40+
private $serializer;
41+
3542
/**
3643
* @param \Magento\Backend\Block\Template\Context $context
3744
* @param \Magento\Catalog\Model\Product\Type $productType
3845
* @param array $data
46+
* @param Json|null $serializer
3947
*/
4048
public function __construct(
4149
\Magento\Backend\Block\Template\Context $context,
4250
\Magento\Catalog\Model\Product\Type $productType,
43-
array $data = []
51+
array $data = [],
52+
Json $serializer = null
4453
) {
4554
$this->_productType = $productType;
55+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
4656
parent::__construct($context, $data);
4757
}
4858

@@ -242,7 +252,7 @@ public function getDisplayOnContainers()
242252
public function getLayoutsChooser()
243253
{
244254
$chooserBlock = $this->getLayout()->createBlock(
245-
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Layout::class
255+
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Layout::class
246256
)->setName(
247257
'widget_instance[<%- data.id %>][pages][layout_handle]'
248258
)->setId(
@@ -268,7 +278,7 @@ public function getLayoutsChooser()
268278
public function getPageLayoutsPageChooser()
269279
{
270280
$chooserBlock = $this->getLayout()->createBlock(
271-
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\DesignAbstraction::class
281+
\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\DesignAbstraction::class
272282
)->setName(
273283
'widget_instance[<%- data.id %>][page_layouts][layout_handle]'
274284
)->setId(
@@ -335,17 +345,26 @@ public function getPageGroups()
335345
$pageGroups = [];
336346
if ($widgetInstance->getPageGroups()) {
337347
foreach ($widgetInstance->getPageGroups() as $pageGroup) {
338-
$pageGroups[] = [
339-
'page_id' => $pageGroup['page_id'],
340-
'group' => $pageGroup['page_group'],
341-
'block' => $pageGroup['block_reference'],
342-
'for_value' => $pageGroup['page_for'],
343-
'layout_handle' => $pageGroup['layout_handle'],
344-
$pageGroup['page_group'] . '_entities' => $pageGroup['entities'],
345-
'template' => $pageGroup['page_template'],
346-
];
348+
$pageGroups[] = $this->serializer->serialize($this->getPageGroup($pageGroup));
347349
}
348350
}
349351
return $pageGroups;
350352
}
353+
354+
/**
355+
* @param array $pageGroup
356+
* @return array
357+
*/
358+
private function getPageGroup(array $pageGroup)
359+
{
360+
return [
361+
'page_id' => $pageGroup['page_id'],
362+
'group' => $pageGroup['page_group'],
363+
'block' => $pageGroup['block_reference'],
364+
'for_value' => $pageGroup['page_for'],
365+
'layout_handle' => $pageGroup['layout_handle'],
366+
$pageGroup['page_group'] . '_entities' => $pageGroup['entities'],
367+
'template' => $pageGroup['page_template'],
368+
];
369+
}
351370
}

app/code/Magento/Widget/view/adminhtml/templates/instance/edit/layout.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ window.WidgetInstance = WidgetInstance;
487487

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

0 commit comments

Comments
 (0)