Skip to content

Commit 94aeb85

Browse files
committed
MAGETWO-99482: Use escaper methods
- refactored $this->helper out of templates
1 parent 7fed3db commit 94aeb85

File tree

6 files changed

+88
-10
lines changed

6 files changed

+88
-10
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Integration\ViewModel;
8+
9+
/**
10+
* JsonSerializer
11+
*/
12+
class JsonSerializer implements \Magento\Framework\View\Element\Block\ArgumentInterface
13+
{
14+
15+
/**
16+
* @var \Magento\Framework\Serialize\Serializer\Json
17+
*/
18+
private $serializer;
19+
20+
/**
21+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
22+
*/
23+
public function __construct(\Magento\Framework\Serialize\Serializer\Json $serializer)
24+
{
25+
$this->serializer = $serializer;
26+
}
27+
28+
/**
29+
* Returns serialized version of data
30+
*
31+
* @param array $data
32+
* @return string
33+
*/
34+
public function serialize(array $data): string
35+
{
36+
return $this->serializer->serialize($data);
37+
}
38+
}

app/code/Magento/Integration/view/adminhtml/templates/resourcetree.phtml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
?>
76

8-
<?php
97
/** @var $block \Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Webapi */
10-
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
118
?>
129

1310
<?= $block->getChildHtml() ?>
@@ -42,7 +39,7 @@ $serializer = new \Magento\Framework\Serialize\Serializer\Json();
4239

4340
<div class="control">
4441
<div class="tree x-tree" data-role="resource-tree" data-mage-init='<?= /* @noEscape */
45-
$serializer->serialize([
42+
$block->getJsonSerializer()->serialize([
4643
'rolesTree' => [
4744
"treeInitData" => $block->getTree(),
4845
"treeInitSelectedData" => $block->getSelectedResources(),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\User\ViewModel;
8+
9+
/**
10+
* JsonSerializer
11+
*/
12+
class JsonSerializer implements \Magento\Framework\View\Element\Block\ArgumentInterface
13+
{
14+
15+
/**
16+
* @var \Magento\Framework\Serialize\Serializer\Json
17+
*/
18+
private $serializer;
19+
20+
/**
21+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
22+
*/
23+
public function __construct(\Magento\Framework\Serialize\Serializer\Json $serializer)
24+
{
25+
$this->serializer = $serializer;
26+
}
27+
28+
/**
29+
* Returns serialized version of data
30+
*
31+
* @param array $data
32+
* @return string
33+
*/
34+
public function serialize(array $data): string
35+
{
36+
return $this->serializer->serialize($data);
37+
}
38+
}

app/code/Magento/User/view/adminhtml/layout/adminhtml_user_role_editrole.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
<body>
1010
<referenceContainer name="left">
1111
<block class="Magento\User\Block\Role\Edit" name="adminhtml.user.editroles">
12-
<block class="Magento\User\Block\Role\Tab\Edit" name="adminhtml.user.tab.rolesedit"/>
12+
<block class="Magento\User\Block\Role\Tab\Edit" name="adminhtml.user.tab.rolesedit">
13+
<arguments>
14+
<argument name="json_serializer" xsi:type="object">Magento\User\ViewModel\JsonSerializer</argument>
15+
</arguments>
16+
</block>
1317
<action method="addTabAfter">
1418
<argument name="name" xsi:type="string">account</argument>
1519
<argument name="block" xsi:type="string">adminhtml.user.tab.rolesedit</argument>

app/code/Magento/User/view/adminhtml/templates/role/edit.phtml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
?>
76

8-
<?php
97
/** @var $block \Magento\User\Block\Role\Tab\Edit */
10-
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
118
?>
129

1310
<?= $block->getChildHtml() ?>
@@ -42,7 +39,7 @@ $serializer = new \Magento\Framework\Serialize\Serializer\Json();
4239

4340
<div class="control">
4441
<div class="tree x-tree" data-role="resource-tree" data-mage-init='<?= /* @noEscape */
45-
$serializer->serialize([
42+
$block->getJsonSerializer()->serialize([
4643
'rolesTree' => [
4744
"treeInitData" => $block->getTree(),
4845
"treeInitSelectedData" => $block->getSelectedResources(),

app/code/Magento/Webapi/view/adminhtml/layout/adminhtml_integration_edit.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
<update handle="editor"/>
1010
<body>
1111
<referenceBlock name="integration_edit_tabs">
12-
<block class="Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Webapi" name="integration_edit_tab_webapi" template="Magento_Integration::resourcetree.phtml"/>
12+
<block class="Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Webapi" name="integration_edit_tab_webapi" template="Magento_Integration::resourcetree.phtml">
13+
<arguments>
14+
<argument name="json_serializer" xsi:type="object">Magento\Integration\ViewModel\JsonSerializer</argument>
15+
</arguments>
16+
</block>
1317
<action method="addTabAfter">
1418
<argument name="name" xsi:type="string">api_section</argument>
1519
<argument name="block" xsi:type="string">integration_edit_tab_webapi</argument>

0 commit comments

Comments
 (0)