Skip to content

Commit

Permalink
Merge pull request #4454 from magento-borg/borg-pr-2.2.10-develop
Browse files Browse the repository at this point in the history
[borg] bug fixes
  • Loading branch information
nathanjosiah authored Jul 10, 2019
2 parents 2a1e51f + 2079d71 commit fdf66c6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 19 deletions.
6 changes: 6 additions & 0 deletions app/code/Magento/Store/Model/System/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public function getStoreValuesForForm($empty = false, $all = false)
}
}
}
array_walk(
$options,
function (&$item) {
$item['__disableTmpl'] = true;
}
);
return $options;
}

Expand Down
9 changes: 5 additions & 4 deletions app/code/Magento/Store/Test/Unit/Model/System/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,15 @@ public function getStoreValuesForFormDataProvider()
'storeGroupId' => $groupId,
'groupWebsiteId' => $websiteId,
'expectedResult' => [
['label' => '', 'value' => ''],
['label' => __('All Store Views'), 'value' => 0],
['label' => $websiteName, 'value' => []],
['label' => '', 'value' => '','__disableTmpl' => true],
['label' => __('All Store Views'), 'value' => 0,'__disableTmpl' => true],
['label' => $websiteName, 'value' => [],'__disableTmpl' => true],
[
'label' => str_repeat($nonEscapableNbspChar, 4) . $groupName,
'value' => [
['label' => str_repeat($nonEscapableNbspChar, 4) . $storeName, 'value' => $storeId]
]
],
'__disableTmpl' => true
],
]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ public function toOptionArray()
return $this->options;
}

/**
* Sanitize website/store option name
*
* @param string $name
*
* @return string
*/
protected function sanitizeName($name)
{
$matches = [];
preg_match('/\$[:]*{(.)*}/', $name, $matches);
if (count($matches) > 0) {
$name = $this->escaper->escapeHtml($this->escaper->escapeJs($name));
} else {
$name = $this->escaper->escapeHtml($name);
}

return $name;
}

/**
* Generate current options
*
Expand All @@ -88,20 +108,20 @@ protected function generateCurrentOptions()
/** @var \Magento\Store\Model\Store $store */
foreach ($storeCollection as $store) {
if ($store->getGroupId() == $group->getId()) {
$name = $this->escaper->escapeHtml($store->getName());
$name = $this->sanitizeName($store->getName());
$stores[$name]['label'] = str_repeat(' ', 8) . $name;
$stores[$name]['value'] = $store->getId();
}
}
if (!empty($stores)) {
$name = $this->escaper->escapeHtml($group->getName());
$name = $this->sanitizeName($group->getName());
$groups[$name]['label'] = str_repeat(' ', 4) . $name;
$groups[$name]['value'] = array_values($stores);
}
}
}
if (!empty($groups)) {
$name = $this->escaper->escapeHtml($website->getName());
$name = $this->sanitizeName($website->getName());
$this->currentOptions[$name]['label'] = $name;
$this->currentOptions[$name]['value'] = array_values($groups);
}
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/grid/editing/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ define([

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

field.__disableTmpl = {
label: true,
options: true
};

return utils.template(field, {
record: this,
column: column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,14 @@ define([
ko.utils.setTextContent(option, allBindings.get('optionsCaption'));
ko.selectExtensions.writeValue(option, undefined);
} else if (typeof arrayEntry[optionsValue] === 'undefined') { // empty value === optgroup
option = utils.template(optgroupTmpl, {
label: arrayEntry[optionsText],
title: arrayEntry[optionsText + 'title']
});
if (arrayEntry.__disableTmpl) {
option = '<optgroup label="' + arrayEntry[optionsText] + '"></optgroup>';
} else {
option = utils.template(optgroupTmpl, {
label: arrayEntry[optionsText],
title: arrayEntry[optionsText + 'title']
});
}
option = ko.utils.parseHtmlFragment(option)[0];

} else {
Expand Down Expand Up @@ -307,6 +311,10 @@ define([
obj.disabled = disabled;
}

if (option.hasOwnProperty('__disableTmpl')) {
obj.__disableTmpl = option.__disableTmpl;
}

label = label.replace(nbspRe, '').trim();

if (Array.isArray(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,32 +234,35 @@ public static function getEntityStoresDataProvider()
null,
['entity_id' => 3, 'store_ids' => [1]],
[
['label' => 'Main Website', 'value' => []],
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
[
'label' => '    Main Website Store',
'value' => [['label' => '    Default Store View', 'value' => 1]]
'value' => [['label' => '    Default Store View', 'value' => 1]],
'__disableTmpl' => true
]
],
],
[
['entity_id' => 2, 'name' => 'product2', 'url_key' => 'product2', 'store_ids' => [1]],
null,
[
['label' => 'Main Website', 'value' => []],
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
[
'label' => '    Main Website Store',
'value' => [['label' => '    Default Store View', 'value' => 1]]
'value' => [['label' => '    Default Store View', 'value' => 1]],
'__disableTmpl' => true
]
]
],
[
['entity_id' => 2, 'name' => 'product2', 'url_key' => 'product2', 'store_ids' => [1]],
['entity_id' => 3, 'name' => 'product3', 'url_key' => 'product3', 'store_ids' => [1]],
[
['label' => 'Main Website', 'value' => []],
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
[
'label' => '    Main Website Store',
'value' => [['label' => '    Default Store View', 'value' => 1]]
'value' => [['label' => '    Default Store View', 'value' => 1]],
'__disableTmpl' => true
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function testGetEntityStores()
$form = $this->_getFormInstance($args);

$expectedStores = [
['label' => 'Main Website', 'value' => []],
['label' => 'Main Website', 'value' => [], '__disableTmpl' => true],
[
'label' => '    Main Website Store',
'value' => [['label' => '    Default Store View', 'value' => 1]]
'value' => [['label' => '    Default Store View', 'value' => 1]],
'__disableTmpl' => true
],
];
$this->assertEquals($expectedStores, $form->getElement('store_id')->getValues());
Expand Down

0 comments on commit fdf66c6

Please sign in to comment.