Skip to content

Commit 18039b9

Browse files
Moving synchronous inline JS into JSON with an external script load.
This aids adoption of CSP by preventing inline JavaScript. However this shouldn't be used elsewhere and should be considered deprecated by default.
1 parent b7c76e3 commit 18039b9

File tree

18 files changed

+58
-25
lines changed

18 files changed

+58
-25
lines changed

app/code/Magento/Checkout/Block/Cart/Shipping.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function getBaseUrl()
9292
/**
9393
* @return bool|string
9494
* @since 100.2.0
95+
* @deprecated
9596
*/
9697
public function getSerializedCheckoutConfig()
9798
{

app/code/Magento/Checkout/Block/Cart/Sidebar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function getConfig()
8989
/**
9090
* @return string
9191
* @since 100.2.0
92+
* @deprecated
9293
*/
9394
public function getSerializedConfig()
9495
{

app/code/Magento/Checkout/Block/Onepage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function getBaseUrl()
117117
/**
118118
* @return bool|string
119119
* @since 100.2.0
120+
* @deprecated
120121
*/
121122
public function getSerializedCheckoutConfig()
122123
{

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
<?= $block->getChildHtml('minicart.addons') ?>
4343
</div>
4444
<?php endif ?>
45-
<script>
46-
window.checkout = <?= /* @escapeNotVerified */ $block->getSerializedConfig() ?>;
47-
</script>
45+
<?= $block->outputLegacyJavaScript('checkout', $block->getConfig()); ?>
4846
<script type="text/x-magento-init">
4947
{
5048
"[data-block='minicart']": {

app/code/Magento/Checkout/view/frontend/templates/cart/shipping.phtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
}
2525
}
2626
</script>
27+
<?= $block->outputLegacyJavaScript('checkoutConfig', $block->getCheckoutConfig()); ?>
2728
<script>
28-
window.checkoutConfig = <?= /* @escapeNotVerified */ $block->getSerializedCheckoutConfig() ?>;
29-
window.customerData = window.checkoutConfig.customerData;
30-
window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
3129
require([
3230
'mage/url',
3331
'Magento_Ui/js/block-loader'

app/code/Magento/Checkout/view/frontend/templates/onepage.phtml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
}
2323
}
2424
</script>
25-
<script>
26-
window.checkoutConfig = <?= /* @escapeNotVerified */ $block->getSerializedCheckoutConfig() ?>;
27-
// Create aliases for customer.js model from customer module
28-
window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
29-
window.customerData = window.checkoutConfig.customerData;
30-
</script>
25+
<?= $block->outputLegacyJavaScript('checkoutConfig', $block->getCheckoutConfig()); ?>
3126
<script>
3227
require([
3328
'mage/url',

app/code/Magento/Customer/Block/Account/AuthenticationPopup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function getConfig()
7070
* Added in scope of https://github.com/magento/magento2/pull/8617
7171
*
7272
* @return bool|string
73+
* @deprecated
7374
* @since 100.2.0
7475
*/
7576
public function getSerializedConfig()

app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
/** @var \Magento\Customer\Block\Account\AuthenticationPopup $block */
1010
?>
1111
<div id="authenticationPopup" data-bind="scope:'authenticationPopup'" style="display: none;">
12-
<script>
13-
window.authenticationPopup = <?= /* @noEscape */ $block->getSerializedConfig() ?>;
14-
</script>
12+
<?= $block->outputLegacyJavaScript('authentication', $block->getConfig()); ?>
1513
<!-- ko template: getTemplate() --><!-- /ko -->
1614
<script type="text/x-magento-init">
1715
{

app/code/Magento/GiftMessage/Block/Cart/GiftOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public function getJsLayout()
7878
*
7979
* @return array
8080
*/
81-
public function getGiftOptionsConfigJson()
81+
public function getGiftOptionsConfig()
8282
{
83-
return $this->jsonEncoder->encode($this->configProvider->getConfig());
83+
return $this->configProvider->getConfig();
8484
}
8585
}
Binary file not shown.

0 commit comments

Comments
 (0)