Skip to content

Commit 017f2e0

Browse files
committed
Merge branch 'MAGETWO-55814' of github.com:magento-east/magento2ce into MAGETWO-55814
2 parents 998ef37 + e745a69 commit 017f2e0

File tree

7 files changed

+76
-53
lines changed

7 files changed

+76
-53
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public function __construct(
3939
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
4040
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
4141
\Magento\Framework\View\LayoutFactory $layoutFactory
42-
)
43-
{
42+
) {
4443
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
4544
$this->resultJsonFactory = $resultJsonFactory;
4645
$this->layoutFactory = $layoutFactory;
@@ -91,13 +90,8 @@ public function execute()
9190
}
9291
}
9392

94-
$options = $this->getRequest()->getParam("option");
95-
if (is_array($options)) {
96-
if (!$this->isUniqueAdminValues($options['value'], $options['delete'])) {
97-
$this->setMessageToResponse($response, [__("The value of Admin must be unique.")]);
98-
$response->setError(true);
99-
};
100-
}
93+
$this->checkUniqueOption($response);
94+
10195
return $this->resultJsonFactory->create()->setJsonData($response->toJson());
10296
}
10397

@@ -109,7 +103,7 @@ public function execute()
109103
*/
110104
private function isUniqueAdminValues(array $optionsValues, array $deletedOptions)
111105
{
112-
$adminValues = array();
106+
$adminValues = [];
113107
foreach ($optionsValues as $optionKey => $values) {
114108
if (!(isset($deletedOptions[$optionKey]) and $deletedOptions[$optionKey] === '1')) {
115109
$adminValues[] = reset($values);
@@ -134,4 +128,18 @@ private function setMessageToResponse($response, $messages)
134128
}
135129
return $response->setData($messageKey, $messages);
136130
}
131+
132+
/**
133+
* @param DataObject $response
134+
* @param array|null $options
135+
* @return $this
136+
*/
137+
private function checkUniqueOption(DataObject $response, array $options = null)
138+
{
139+
if (is_array($options) and !$this->isUniqueAdminValues($options['value'], $options['delete'])) {
140+
$this->setMessageToResponse($response, [__("The value of Admin must be unique.")]);
141+
$response->setError(true);
142+
}
143+
return $this;
144+
}
137145
}

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@
1111
$stores = $block->getStoresSortedBySortOrder();
1212
?>
1313
<fieldset class="fieldset">
14-
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Manage Options (Values of Your Attribute)') ?></span></legend>
14+
<legend class="legend">
15+
<span><?php echo $block->escapeHtml(__('Manage Options (Values of Your Attribute)')); ?></span>
16+
</legend>
1517
<div id="manage-options-panel" data-index="attribute_options_select_container">
1618
<table class="admin__control-table" data-index="attribute_options_select">
1719
<thead>
1820
<tr id="attribute-options-table">
1921
<th class="col-draggable"></th>
20-
<th class="col-default control-table-actions-th"><span><?php /* @escapeNotVerified */ echo __('Is Default') ?></span></th>
22+
<th class="col-default control-table-actions-th">
23+
<span><?php echo $block->escapeHtml(__('Is Default')); ?></span>
24+
</th>
2125
<?php
2226
foreach ($stores as $_store): ?>
2327
<th<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> class="_required"<?php endif; ?>>
24-
<span><?php /* @escapeNotVerified */ echo __($_store->getName()) ?></span>
28+
<span><?php echo $block->escapeHtml(__($_store->getName())) ?></span>
2529
</th>
2630
<?php endforeach;
2731
$storetotal = count($stores) + 3;
@@ -32,17 +36,18 @@ $stores = $block->getStoresSortedBySortOrder();
3236
<tbody data-role="options-container" class="ignore-validate"></tbody>
3337
<tfoot>
3438
<tr>
35-
<th colspan="<?php /* @escapeNotVerified */ echo $storetotal; ?>" class="validation">
39+
<th colspan="<?php echo (int)$storetotal; ?>" class="validation">
3640
<input type="hidden" class="required-dropdown-attribute-entry" name="dropdown_attribute_validation"/>
3741
<input type="hidden" class="required-dropdown-attribute-unique" name="dropdown_attribute_validation_unique"/>
3842
</th>
3943
</tr>
4044
<tr>
41-
<th colspan="<?php /* @escapeNotVerified */ echo $storetotal; ?>" class="col-actions-add">
45+
<th colspan="<?php echo (int) $storetotal; ?>" class="col-actions-add">
4246
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
43-
<button id="add_new_option_button" data-action="add_new_row" title="<?php /* @escapeNotVerified */ echo __('Add Option'); ?>"
44-
type="button" class="action- scalable add">
45-
<span><?php /* @escapeNotVerified */ echo __('Add Option'); ?></span>
47+
<button id="add_new_option_button" data-action="add_new_row"
48+
title="<?php echo $block->escapeHtml(__('Add Option')); ?>"
49+
type="button" class="action- scalable add">
50+
<span><?php echo $block->escapeHtml(__('Add Option')); ?></span>
4651
</button>
4752
<?php endif; ?>
4853
</th>
@@ -55,23 +60,25 @@ $stores = $block->getStoresSortedBySortOrder();
5560
<tr>
5661
<td class="col-draggable">
5762
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()): ?>
58-
<div data-role="draggable-handle" class="draggable-handle" title="<?php /* @escapeNotVerified */ echo __('Sort Option'); ?>"></div>
63+
<div data-role="draggable-handle" class="draggable-handle"
64+
title="<?php echo $block->escapeHtml(__('Sort Option')); ?>">
65+
</div>
5966
<?php endif; ?>
6067
<input data-role="order" type="hidden" name="option[order][<%- data.id %>]" value="<%- data.sort_order %>" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()): ?> disabled="disabled"<?php endif; ?>/>
6168
</td>
6269
<td class="col-default control-table-actions-cell">
6370
<input class="input-radio" type="<%- data.intype %>" name="default[]" value="<%- data.id %>" <%- data.checked %><?php if ($block->getReadOnly()):?>disabled="disabled"<?php endif;?>/>
6471
</td>
6572
<?php foreach ($stores as $_store): ?>
66-
<td class="col-<%- data.id %>"><input name="option[value][<%- data.id %>][<?php /* @escapeNotVerified */ echo $_store->getId() ?>]" value="<%- data.store<?php /* @escapeNotVerified */ echo $_store->getId() ?> %>" class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option required-unique<?php endif; ?>" type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif;?>/></td>
73+
<td class="col-<%- data.id %>"><input name="option[value][<%- data.id %>][<?php echo (int) $_store->getId() ?>]" value="<%- data.store<?php /* @noEscape */ echo (int) $_store->getId() ?> %>" class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option required-unique<?php endif; ?>" type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif;?>/></td>
6774
<?php endforeach; ?>
6875
<td id="delete_button_container_<%- data.id %>" class="col-delete">
6976
<input type="hidden" class="delete-flag" name="option[delete][<%- data.id %>]" value="" />
7077
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
71-
<button id="delete_button_<%- data.id %>" title="<?php /* @escapeNotVerified */ echo __('Delete') ?>" type="button"
78+
<button id="delete_button_<%- data.id %>" title="<?php echo $block->escapeHtml(__('Delete'));?>" type="button"
7279
class="action- scalable delete delete-option"
7380
>
74-
<span><?php /* @escapeNotVerified */ echo __('Delete') ?></span>
81+
<span><?php echo $block->escapeHtml(__('Delete')) ?></span>
7582
</button>
7683
<?php endif;?>
7784
</td>
@@ -94,7 +101,7 @@ $stores = $block->getStoresSortedBySortOrder();
94101
},
95102
"Magento_Catalog/catalog/product/attribute/unique-validate": {
96103
"element": "required-dropdown-attribute-unique",
97-
"message": "<?php echo __("The value of Admin must be unique.") ?>"
104+
"message": "<?php echo $block->escapeHtml(__("The value of Admin must be unique.")); ?>"
98105
}
99106
}
100107
}

app/code/Magento/Catalog/view/adminhtml/web/catalog/product/attribute/unique-validate.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
/* global $break $ $$ */
7-
86
define([
97
'jquery',
108
'mage/backend/validation'
@@ -14,28 +12,30 @@ define([
1412
return function (config) {
1513
var _config = jQuery.extend({
1614
element: null,
17-
message: "",
15+
message: '',
1816
uniqueClass: 'required-unique'
1917
}, config);
2018

21-
if (typeof _config.element === "string") {
19+
if (typeof _config.element === 'string') {
2220
jQuery.validator.addMethod(
2321
_config.element,
2422

2523
function (value, element) {
2624
var inputs = jQuery(element)
27-
.closest("table")
28-
.find('.' + _config.uniqueClass + ":visible"),
25+
.closest('table')
26+
.find('.' + _config.uniqueClass + ':visible'),
2927
valuesHash = {},
3028
isValid = true;
3129

3230
inputs.each(function (el) {
3331
var inputValue = inputs[el].value;
34-
if (typeof valuesHash[inputValue] !== "undefined") {
32+
33+
if (typeof valuesHash[inputValue] !== 'undefined') {
3534
isValid = false;
3635
}
3736
valuesHash[inputValue] = el;
3837
});
38+
3939
return isValid;
4040
},
4141

app/code/Magento/Swatches/Controller/Adminhtml/Product/Attribute/Plugin/Validate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Validate
1919
/**
2020
* @param Attribute\Validate $subject
2121
* @param Json $response
22-
* @return array
22+
* @return \Magento\Framework\Controller\ResultInterface
2323
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2424
*/
2525
public function afterExecute(Attribute\Validate $subject, Json $response)
@@ -57,7 +57,7 @@ public function afterExecute(Attribute\Validate $subject, Json $response)
5757
*/
5858
private function isUniqueAdminValues(array $optionsValues, array $deletedOptions)
5959
{
60-
$adminValues = array();
60+
$adminValues = [];
6161
foreach ($optionsValues as $optionKey => $values) {
6262
if (!(isset($deletedOptions[$optionKey]) and $deletedOptions[$optionKey] === '1')) {
6363
$adminValues[] = reset($values);

app/code/Magento/Swatches/Test/Unit/Controller/Adminhtml/Product/Attribute/Plugin/ValidateTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function testAfterExecute(array $dataRequest, $isError)
5353
$controller->afterExecute($subject, $response);
5454
}
5555

56+
/**
57+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
58+
* @return array
59+
*/
5660
public function providerData()
5761
{
5862
return [

app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/text.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ $stores = $block->getStoresSortedBySortOrder();
8888
value="<%- data.store<?php /* @noEscape */ echo $storeId; ?> %>"
8989
class="input-text<?php if ($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>"
9090
type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif;?>
91-
placeholder="<?php echo __("Description"); ?>" />
91+
placeholder="<?php echo $block->escapeHtml(__("Description")); ?>"/>
9292
</td>
9393
<?php endforeach; ?>
9494
<td id="delete_button_swatch_container_<%- data.id %>" class="col-delete">
@@ -108,7 +108,7 @@ $stores = $block->getStoresSortedBySortOrder();
108108
"Magento_Swatches/js/text": <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?> ,
109109
"Magento_Catalog/catalog/product/attribute/unique-validate": {
110110
"element": "required-text-swatch-unique",
111-
"message": "<?php echo __("The value of Admin must be unique.") ?>"
111+
"message": "<?php echo $block->escapeHtml(__("The value of Admin must be unique.")); ?>"
112112
}
113113
}
114114
}

0 commit comments

Comments
 (0)