Skip to content

Commit d59ce32

Browse files
authored
Merge pull request #4453 from magento-borg/borg-pr-2.3.3-develop
[borg] bug fixes
2 parents a5bab5a + a7432e4 commit d59ce32

File tree

7 files changed

+71
-19
lines changed

7 files changed

+71
-19
lines changed

app/code/Magento/Store/Model/System/Store.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function getStoreValuesForForm($empty = false, $all = false)
118118
$options[] = ['label' => __('All Store Views'), 'value' => 0];
119119
}
120120

121+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
121122
$nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
122123

123124
foreach ($this->_websiteCollection as $website) {
@@ -152,6 +153,12 @@ public function getStoreValuesForForm($empty = false, $all = false)
152153
}
153154
}
154155
}
156+
array_walk(
157+
$options,
158+
function (&$item) {
159+
$item['__disableTmpl'] = true;
160+
}
161+
);
155162
return $options;
156163
}
157164

@@ -398,6 +405,7 @@ public function getStoreCollection()
398405

399406
/**
400407
* Load/Reload collection(s) by type
408+
*
401409
* Allowed types: website, group, store or null for all
402410
*
403411
* @param string $type

app/code/Magento/Store/Test/Unit/Model/System/StoreTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Store\Test\Unit\Model\System;
88

9+
/**
10+
* Class StoreTest covers Magento\Store\Model\System\Store.
11+
*/
912
class StoreTest extends \PHPUnit\Framework\TestCase
1013
{
1114
/**
@@ -262,14 +265,15 @@ public function getStoreValuesForFormDataProvider()
262265
'storeGroupId' => $groupId,
263266
'groupWebsiteId' => $websiteId,
264267
'expectedResult' => [
265-
['label' => '', 'value' => ''],
266-
['label' => __('All Store Views'), 'value' => 0],
267-
['label' => $websiteName, 'value' => []],
268+
['label' => '', 'value' => '','__disableTmpl' => true],
269+
['label' => __('All Store Views'), 'value' => 0,'__disableTmpl' => true],
270+
['label' => $websiteName, 'value' => [],'__disableTmpl' => true],
268271
[
269272
'label' => str_repeat($nonEscapableNbspChar, 4) . $groupName,
270273
'value' => [
271274
['label' => str_repeat($nonEscapableNbspChar, 4) . $storeName, 'value' => $storeId]
272-
]
275+
],
276+
'__disableTmpl' => true
273277
],
274278
]
275279
],

app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ public function toOptionArray()
6868
return $this->options;
6969
}
7070

71+
/**
72+
* Sanitize website/store option name
73+
*
74+
* @param string $name
75+
*
76+
* @return string
77+
*/
78+
protected function sanitizeName($name)
79+
{
80+
$matches = [];
81+
preg_match('/\$[:]*{(.)*}/', $name, $matches);
82+
if (count($matches) > 0) {
83+
$name = $this->escaper->escapeHtml($this->escaper->escapeJs($name));
84+
} else {
85+
$name = $this->escaper->escapeHtml($name);
86+
}
87+
88+
return $name;
89+
}
90+
7191
/**
7292
* Generate current options
7393
*
@@ -88,20 +108,20 @@ protected function generateCurrentOptions()
88108
/** @var \Magento\Store\Model\Store $store */
89109
foreach ($storeCollection as $store) {
90110
if ($store->getGroupId() == $group->getId()) {
91-
$name = $this->escaper->escapeHtml($store->getName());
111+
$name = $this->sanitizeName($store->getName());
92112
$stores[$name]['label'] = str_repeat(' ', 8) . $name;
93113
$stores[$name]['value'] = $store->getId();
94114
}
95115
}
96116
if (!empty($stores)) {
97-
$name = $this->escaper->escapeHtml($group->getName());
117+
$name = $this->sanitizeName($group->getName());
98118
$groups[$name]['label'] = str_repeat(' ', 4) . $name;
99119
$groups[$name]['value'] = array_values($stores);
100120
}
101121
}
102122
}
103123
if (!empty($groups)) {
104-
$name = $this->escaper->escapeHtml($website->getName());
124+
$name = $this->sanitizeName($website->getName());
105125
$this->currentOptions[$name]['label'] = $name;
106126
$this->currentOptions[$name]['value'] = array_values($groups);
107127
}

app/code/Magento/Ui/view/base/web/js/grid/editing/record.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ define([
134134

135135
field = utils.extend({}, fields.base, field);
136136

137+
field.__disableTmpl = {
138+
label: true,
139+
options: true
140+
};
141+
137142
return utils.template(field, {
138143
record: this,
139144
column: column

app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,14 @@ define([
222222
ko.utils.setTextContent(option, allBindings.get('optionsCaption'));
223223
ko.selectExtensions.writeValue(option, undefined);
224224
} else if (typeof arrayEntry[optionsValue] === 'undefined') { // empty value === optgroup
225-
option = utils.template(optgroupTmpl, {
226-
label: arrayEntry[optionsText],
227-
title: arrayEntry[optionsText + 'title']
228-
});
225+
if (arrayEntry.__disableTmpl) {
226+
option = '<optgroup label="' + arrayEntry[optionsText] + '"></optgroup>';
227+
} else {
228+
option = utils.template(optgroupTmpl, {
229+
label: arrayEntry[optionsText],
230+
title: arrayEntry[optionsText + 'title']
231+
});
232+
}
229233
option = ko.utils.parseHtmlFragment(option)[0];
230234

231235
} else {
@@ -307,6 +311,10 @@ define([
307311
obj.disabled = disabled;
308312
}
309313

314+
if (option.hasOwnProperty('__disableTmpl')) {
315+
obj.__disableTmpl = option.__disableTmpl;
316+
}
317+
310318
label = label.replace(nbspRe, '').trim();
311319

312320
if (Array.isArray(value)) {

dev/tests/integration/testsuite/Magento/UrlRewrite/Block/Catalog/Edit/FormTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public function testGetEntityStoresCategoryStoresException()
190190
*
191191
* @static
192192
* @return array
193+
* phpcs:disable Magento2.Functions.StaticFunction
193194
*/
194195
public static function formPostInitDataProvider()
195196
{
@@ -226,6 +227,7 @@ public static function formPostInitDataProvider()
226227
*
227228
* @static
228229
* @return array
230+
* phpcs:disable Magento2.Functions.StaticFunction
229231
*/
230232
public static function getEntityStoresDataProvider()
231233
{
@@ -234,32 +236,35 @@ public static function getEntityStoresDataProvider()
234236
null,
235237
['entity_id' => 3, 'store_ids' => [1]],
236238
[
237-
['label' => 'Main Website', 'value' => []],
239+
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
238240
[
239241
'label' => '    Main Website Store',
240-
'value' => [['label' => '    Default Store View', 'value' => 1]]
242+
'value' => [['label' => '    Default Store View', 'value' => 1]],
243+
'__disableTmpl' => true
241244
]
242245
],
243246
],
244247
[
245248
['entity_id' => 2, 'name' => 'product2', 'url_key' => 'product2', 'store_ids' => [1]],
246249
null,
247250
[
248-
['label' => 'Main Website', 'value' => []],
251+
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
249252
[
250253
'label' => '    Main Website Store',
251-
'value' => [['label' => '    Default Store View', 'value' => 1]]
254+
'value' => [['label' => '    Default Store View', 'value' => 1]],
255+
'__disableTmpl' => true
252256
]
253257
]
254258
],
255259
[
256260
['entity_id' => 2, 'name' => 'product2', 'url_key' => 'product2', 'store_ids' => [1]],
257261
['entity_id' => 3, 'name' => 'product3', 'url_key' => 'product3', 'store_ids' => [1]],
258262
[
259-
['label' => 'Main Website', 'value' => []],
263+
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
260264
[
261265
'label' => '    Main Website Store',
262-
'value' => [['label' => '    Default Store View', 'value' => 1]]
266+
'value' => [['label' => '    Default Store View', 'value' => 1]],
267+
'__disableTmpl' => true
263268
]
264269
]
265270
]

dev/tests/integration/testsuite/Magento/UrlRewrite/Block/Cms/Page/Edit/FormTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ public function testGetEntityStores()
7878
$form = $this->_getFormInstance($args);
7979

8080
$expectedStores = [
81-
['label' => 'Main Website', 'value' => []],
81+
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
8282
[
8383
'label' => '    Main Website Store',
84-
'value' => [['label' => '    Default Store View', 'value' => 1]]
84+
'value' => [['label' => '    Default Store View', 'value' => 1]],
85+
'__disableTmpl' => true
8586
],
8687
];
8788
$this->assertEquals($expectedStores, $form->getElement('store_id')->getValues());
@@ -110,6 +111,7 @@ public function testGetEntityStoresProductStoresException()
110111
*
111112
* @static
112113
* @return array
114+
* phpcs:disable Magento2.Functions.StaticFunction
113115
*/
114116
public static function formPostInitDataProvider()
115117
{

0 commit comments

Comments
 (0)