Skip to content

Commit 50329e2

Browse files
committed
MAGETWO-99286: Eliminate @escapeNotVerified in Magento_Swatches module
1 parent b8f137d commit 50329e2

File tree

7 files changed

+63
-74
lines changed

7 files changed

+63
-74
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// phpcs:disable Magento2.Files.LineLength
87
// phpcs:disable Magento2.Templates.ThisInTemplate
98
?>
109
<script type="text/x-magento-init">

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

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

7-
// phpcs:disable Magento2.Files.LineLength
8-
97
/** @var $block \Magento\Swatches\Block\Adminhtml\Attribute\Edit\Options\Text */
108

119
$stores = $block->getStoresSortedBySortOrder();

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
/** @var $block \Magento\Swatches\Block\Adminhtml\Attribute\Edit\Options\Visual */
108

119
$stores = $block->getStoresSortedBySortOrder();
1210
?>
1311
<fieldset class="admin__fieldset fieldset">
1412
<legend class="legend">
15-
<span><?= $block->escapeHtml( __('Manage Swatch (Values of Your Attribute)')) ?></span>
13+
<span><?= $block->escapeHtml(__('Manage Swatch (Values of Your Attribute)')) ?></span>
1614
</legend><br />
1715
<div class="admin__control-table-wrapper" id="swatch-visual-options-panel">
1816
<table class="data-table clearfix" cellspacing="0">
@@ -21,13 +19,12 @@ $stores = $block->getStoresSortedBySortOrder();
2119
<th class="col-draggable"></th>
2220
<th class="col-default"><span><?= $block->escapeHtml(__('Is Default')) ?></span></th>
2321
<th><span><?= $block->escapeHtml(__('Swatch')) ?></span></th>
24-
<?php foreach ($stores as $_store): ?>
25-
<th<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> class="_required"<?php endif; ?>>
22+
<?php foreach ($stores as $_store) : ?>
23+
<th<?= ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID) ? ' class="_required"' : '' ?>
2624
<span><?= $block->escapeHtml($_store->getName()) ?></span>
2725
</th>
28-
<?php endforeach;
29-
$colTotal = count($stores) * 2 + 3;
30-
?>
26+
<?php endforeach; ?>
27+
<?php $colTotal = count($stores) * 2 + 3; ?>
3128
<th class="col-delete">&nbsp;</th>
3229
</tr>
3330
</thead>
@@ -41,7 +38,7 @@ $stores = $block->getStoresSortedBySortOrder();
4138
</tr>
4239
<tr>
4340
<th colspan="<?= (int)$colTotal ?>" class="col-actions-add">
44-
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()): ?>
41+
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()) : ?>
4542
<button id="add_new_swatch_visual_option_button"
4643
title="<?= $block->escapeHtml(__('Add Swatch')) ?>"
4744
type="button" class="action- scalable add">
@@ -57,14 +54,14 @@ $stores = $block->getStoresSortedBySortOrder();
5754
<script id="swatch-visual-row-template" type="text/x-magento-template">
5855
<tr>
5956
<td class="col-draggable">
60-
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()): ?>
57+
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()) : ?>
6158
<div data-role="draggable-handle" class="draggable-handle"
6259
title="<?= $block->escapeHtml(__('Sort Option')) ?>"></div>
6360
<?php endif; ?>
64-
<input data-role="order" type="hidden" name="optionvisual[order][<%- data.id %>]" value="<%- data.sort_order %>" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()): ?> disabled="disabled"<?php endif; ?>/>
61+
<input data-role="order" type="hidden" name="optionvisual[order][<%- data.id %>]" value="<%- data.sort_order %>" <?= ($block->getReadOnly() || $block->canManageOptionDefaultOnly()) ? ' disabled="disabled"' : '' ?>/>
6562
</td>
6663
<td class="col-default">
67-
<input class="input-radio" type="<%- data.intype %>" name="defaultvisual[]" value="<%- data.id %>" <%- data.checked %><?php if ($block->getReadOnly()):?>disabled="disabled"<?php endif;?>/>
64+
<input class="input-radio" type="<%- data.intype %>" name="defaultvisual[]" value="<%- data.id %>" <%- data.checked %><?= ($block->getReadOnly()) ? ' disabled="disabled"' : '' ?>/>
6865
</td>
6966
<td class="swatches-visual-col col-default <%- data.empty_class %>">
7067
<?php //@todo add logic getting swatch value from db */ ?>
@@ -88,17 +85,17 @@ $stores = $block->getStoresSortedBySortOrder();
8885
</div>
8986
</div>
9087
</td>
91-
<?php foreach ($stores as $_store): ?>
88+
<?php foreach ($stores as $_store) : ?>
9289
<td class="swatch-col-<%- data.id %>">
9390
<input name="optionvisual[value][<%- data.id %>][<?= (int)$_store->getId() ?>]"
9491
value="<%- data.store<?= (int) $_store->getId() ?> %>"
95-
class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option required-unique<?php endif; ?>"
96-
type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()): ?> disabled="disabled"<?php endif; ?>/>
92+
class="input-text<?= ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID) ? ' required-option required-unique' : '' ?>"
93+
type="text" <?= ($block->getReadOnly() || $block->canManageOptionDefaultOnly()) ? ' disabled="disabled"' : '' ?>/>
9794
</td>
9895
<?php endforeach; ?>
9996
<td id="delete_button_swatch_container_<%- data.id %>" class="col-delete">
10097
<input type="hidden" class="delete-flag" name="optionvisual[delete][<%- data.id %>]" value="" />
101-
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
98+
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()) : ?>
10299
<button title="<?= $block->escapeHtml(__('Delete')) ?>" type="button"
103100
class="action- scalable delete delete-option">
104101
<span><?= $block->escapeHtml(__('Delete')) ?></span>

app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/edit/attribute/steps/attributes_values.phtml

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

7-
// phpcs:disable Magento2.Files.LineLength
8-
97
/* @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues */
108
?>
119
<div data-bind="scope: '<?= $block->escapeHtmlAttr($block->getComponentName()) ?>'">

app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,69 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
7+
// phpcs:disable PSR2.ControlStructures.SwitchDeclaration
8+
// phpcs:disable Generic.WhiteSpace.ScopeIndent
89

910
/** @var $block \Magento\Swatches\Block\LayeredNavigation\RenderLayered */
1011
?>
1112
<?php $swatchData = $block->getSwatchData(); ?>
12-
<div class="swatch-attribute swatch-layered <?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>"
13-
attribute-code="<?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>"
14-
attribute-id="<?= /* @escapeNotVerified */ $swatchData['attribute_id'] ?>">
13+
<div class="swatch-attribute swatch-layered <?= $block->escapeHtmlAttr($swatchData['attribute_code']) ?>"
14+
attribute-code="<?= $block->escapeHtmlAttr($swatchData['attribute_code']) ?>"
15+
attribute-id="<?= $block->escapeHtmlAttr($swatchData['attribute_id']) ?>">
1516
<div class="swatch-attribute-options clearfix">
16-
<?php foreach ($swatchData['options'] as $option => $label): ?>
17-
<a href="<?= /* @escapeNotVerified */ $label['link'] ?>"
18-
aria-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
17+
<?php foreach ($swatchData['options'] as $option => $label) : ?>
18+
<a href="<?= $block->escapeUrl($label['link']) ?>"
19+
aria-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
1920
class="swatch-option-link-layered">
20-
<?php if (isset($swatchData['swatches'][$option]['type'])): ?>
21+
<?php if (isset($swatchData['swatches'][$option]['type'])) : ?>
2122
<?php switch ($swatchData['swatches'][$option]['type']) {
2223
case '3':
2324
?>
24-
<div class="swatch-option <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
25+
<div class="swatch-option <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
2526
tabindex="-1"
2627
option-type="3"
27-
option-id="<?= /* @escapeNotVerified */ $option ?>"
28-
option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
28+
option-id="<?= $block->escapeHtmlAttr($option) ?>"
29+
option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
2930
option-tooltip-thumb=""
3031
option-tooltip-value=""
3132
></div>
32-
<?php break;
33+
<?php break;
3334
case '2':
3435
?>
3536
<?php $swatchThumbPath = $block->getSwatchPath('swatch_thumb', $swatchData['swatches'][$option]['value']); ?>
3637
<?php $swatchImagePath = $block->getSwatchPath('swatch_image', $swatchData['swatches'][$option]['value']); ?>
37-
<div class="swatch-option image <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
38+
<div class="swatch-option image <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
3839
tabindex="-1"
3940
option-type="2"
40-
option-id="<?= /* @escapeNotVerified */ $option ?>"
41-
option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
42-
option-tooltip-thumb="<?= /* @escapeNotVerified */ $swatchThumbPath ?>"
41+
option-id="<?= $block->escapeHtmlAttr($option) ?>"
42+
option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
43+
option-tooltip-thumb="<?= $block->escapeUrl($swatchThumbPath) ?>"
4344
option-tooltip-value=""
44-
style="background: url(<?= /* @escapeNotVerified */ $swatchImagePath ?>) no-repeat center; background-size: initial;"></div>
45-
<?php break;
45+
style="background: url(<?= $block->escapeUrl($swatchImagePath) ?>) no-repeat center; background-size: initial;"></div>
46+
<?php break;
4647
case '1':
4748
?>
48-
<div class="swatch-option color <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
49+
<div class="swatch-option color <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
4950
tabindex="-1"
5051
option-type="1"
51-
option-id="<?= /* @escapeNotVerified */ $option ?>"
52-
option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
52+
option-id="<?= $block->escapeHtmlAttr($option) ?>"
53+
option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
5354
option-tooltip-thumb=""
54-
option-tooltip-value="<?= /* @escapeNotVerified */ $swatchData['swatches'][$option]['value'] ?>"
55-
style="background: <?= /* @escapeNotVerified */ $swatchData['swatches'][$option]['value'] ?> no-repeat center; background-size: initial;"></div>
56-
<?php break;
55+
option-tooltip-value="<?= $block->escapeHtmlAttr($swatchData['swatches'][$option]['value']) ?>"
56+
style="background: <?= $block->escapeHtmlAttr($swatchData['swatches'][$option]['value']) ?> no-repeat center; background-size: initial;"></div>
57+
<?php break;
5758
case '0':
5859
default:
5960
?>
60-
<div class="swatch-option text <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
61-
tabindex="-1"
62-
option-type="0"
63-
option-id="<?= /* @escapeNotVerified */ $option ?>"
64-
option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
65-
option-tooltip-thumb=""
66-
option-tooltip-value=""
67-
><?= /* @escapeNotVerified */ $swatchData['swatches'][$option]['value'] ?></div>
68-
<?php break;
61+
<div class="swatch-option text <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
62+
tabindex="-1"
63+
option-type="0"
64+
option-id="<?= $block->escapeHtmlAttr($option) ?>"
65+
option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
66+
option-tooltip-thumb=""
67+
option-tooltip-value=""
68+
><?= $block->escapeHtml($swatchData['swatches'][$option]['value']) ?></div>
69+
<?php break;
6970
} ?>
7071
<?php endif; ?>
7172
</a>
@@ -75,7 +76,7 @@
7576

7677
<script>
7778
require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer"], function ($) {
78-
$('.swatch-layered.<?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>')
79+
$('.swatch-layered.<?= $block->escapeJs($swatchData['attribute_code']) ?>')
7980
.find('[option-type="1"], [option-type="2"], [option-type="0"], [option-type="3"]')
8081
.SwatchRendererTooltip();
8182
});

app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
/** @var $block \Magento\Swatches\Block\Product\Renderer\Listing\Configurable */
99
$productId = $block->getProduct()->getId();
1010
?>
11-
<div class="swatch-opt-<?= /* @escapeNotVerified */ $productId ?>"
12-
data-role="swatch-option-<?= /* @escapeNotVerified */ $productId ?>"></div>
11+
<div class="swatch-opt-<?= $block->escapeHtmlAttr($productId) ?>"
12+
data-role="swatch-option-<?= $block->escapeHtmlAttr($productId) ?>"></div>
1313

1414
<script type="text/x-magento-init">
1515
{
16-
"[data-role=swatch-option-<?= /* @escapeNotVerified */ $productId ?>]": {
16+
"[data-role=swatch-option-<?= $block->escapeJs($productId) ?>]": {
1717
"Magento_Swatches/js/swatch-renderer": {
1818
"selectorProduct": ".product-item-details",
1919
"onlySwatches": true,
2020
"enableControlLabel": false,
21-
"numberToShow": <?= /* @escapeNotVerified */ $block->getNumberSwatchesPerProduct(); ?>,
22-
"jsonConfig": <?= /* @escapeNotVerified */ $block->getJsonConfig(); ?>,
23-
"jsonSwatchConfig": <?= /* @escapeNotVerified */ $block->getJsonSwatchConfig(); ?>,
24-
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>",
21+
"numberToShow": <?= $block->escapeJs($block->getNumberSwatchesPerProduct()) ?>,
22+
"jsonConfig": <?= /* @noEscape */ $block->getJsonConfig() ?>,
23+
"jsonSwatchConfig": <?= /* @noEscape */ $block->getJsonSwatchConfig() ?>,
24+
"mediaCallback": "<?= $block->escapeJs($block->escapeUrl($block->getMediaCallback())) ?>",
2525
"jsonSwatchImageSizeConfig": <?= /* @noEscape */ $block->getJsonSwatchSizeConfig() ?>
2626
}
2727
}
@@ -30,11 +30,11 @@ $productId = $block->getProduct()->getId();
3030

3131
<script type="text/x-magento-init">
3232
{
33-
"[data-role=priceBox][data-price-box=product-id-<?= /* @escapeNotVerified */ $productId ?>]": {
33+
"[data-role=priceBox][data-price-box=product-id-<?= $block->escapeJs($productId) ?>]": {
3434
"priceBox": {
3535
"priceConfig": {
36-
"priceFormat": <?= /* @escapeNotVerified */ $block->getPriceFormatJson(); ?>,
37-
"prices": <?= /* @escapeNotVerified */ $block->getPricesJson(); ?>
36+
"priceFormat": <?= /* @noEscape */ $block->getPriceFormatJson(); ?>,
37+
"prices": <?= /* @noEscape */ $block->getPricesJson(); ?>
3838
}
3939
}
4040
}

app/code/Magento/Swatches/view/frontend/templates/product/view/renderer.phtml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
// @codingStandardsIgnoreFile
7-
//"swatchRenderer": {
86
?>
97
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?>
108
<div class="swatch-opt" data-role="swatch-options"></div>
@@ -13,13 +11,11 @@
1311
{
1412
"[data-role=swatch-options]": {
1513
"Magento_Swatches/js/swatch-renderer": {
16-
"jsonConfig": <?= /* @escapeNotVerified */ $swatchOptions = $block->getJsonConfig() ?>,
17-
"jsonSwatchConfig": <?php /* @escapeNotVerified */
18-
echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
19-
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>",
20-
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
21-
'Magento_ConfigurableProduct') ?: 'replace'; ?>",
22-
"jsonSwatchImageSizeConfig": <?php /* @noEscape */ echo $block->getJsonSwatchSizeConfig() ?>
14+
"jsonConfig": <?= /* @noEscape */ $swatchOptions = $block->getJsonConfig() ?>,
15+
"jsonSwatchConfig": <?=/* @noEscape */ $swatchOptions = $block->getJsonSwatchConfig() ?>,
16+
"mediaCallback": "<?= $block->escapeJs($block->escapeUrl($block->getMediaCallback())) ?>",
17+
"gallerySwitchStrategy": "<?= $block->escapeJs($block->getVar('gallery_switch_strategy', 'Magento_ConfigurableProduct')) ?: 'replace'; ?>",
18+
"jsonSwatchImageSizeConfig": <?= /* @noEscape */ $block->getJsonSwatchSizeConfig() ?>
2319
}
2420
},
2521
"*" : {

0 commit comments

Comments
 (0)