Skip to content

Commit 350487b

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-65232-V3' into EPAM-PR-81
2 parents e8d1ccd + 424321e commit 350487b

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Ui\DataProvider\Product\Modifier;
9+
10+
use Magento\Framework\Escaper;
11+
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
12+
13+
/**
14+
* Modify product listing attributes
15+
*/
16+
class Attributes implements ModifierInterface
17+
{
18+
/**
19+
* @var Escaper
20+
*/
21+
private $escaper;
22+
23+
/**
24+
* @var array
25+
*/
26+
private $escapeAttributes;
27+
28+
/**
29+
* @param Escaper $escaper
30+
* @param array $escapeAttributes
31+
*/
32+
public function __construct(
33+
Escaper $escaper,
34+
array $escapeAttributes = []
35+
) {
36+
$this->escaper = $escaper;
37+
$this->escapeAttributes = $escapeAttributes;
38+
}
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
public function modifyData(array $data)
44+
{
45+
if (!empty($data) && !empty($this->escapeAttributes)) {
46+
foreach ($data['items'] as &$item) {
47+
foreach ($this->escapeAttributes as $escapeAttribute) {
48+
if (isset($item[$escapeAttribute])) {
49+
$item[$escapeAttribute] = $this->escaper->escapeHtml($item[$escapeAttribute]);
50+
}
51+
}
52+
}
53+
}
54+
return $data;
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function modifyMeta(array $meta)
61+
{
62+
return $meta;
63+
}
64+
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,24 @@
166166
<argument name="pool" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool</argument>
167167
</arguments>
168168
</type>
169-
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool"/>
169+
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool">
170+
<arguments>
171+
<argument name="modifiers" xsi:type="array">
172+
<item name="attributes" xsi:type="array">
173+
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Modifier\Attributes</item>
174+
<item name="sortOrder" xsi:type="number">10</item>
175+
</item>
176+
</argument>
177+
</arguments>
178+
</virtualType>
179+
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\Attributes">
180+
<arguments>
181+
<argument name="escapeAttributes" xsi:type="array">
182+
<item name="name" xsi:type="string">name</item>
183+
<item name="sku" xsi:type="string">sku</item>
184+
</argument>
185+
</arguments>
186+
</type>
170187
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions">
171188
<arguments>
172189
<argument name="scopeName" xsi:type="string">product_form.product_form</argument>

0 commit comments

Comments
 (0)