Skip to content

Commit a9b473d

Browse files
ENGCOM-6581: Remove extraneous whitespace - #26275 #26285
- Merge Pull Request #26285 from DanielRuf/magento2:fix/26275-checkout-required-fields-remove-space - Merged commits: 1. d9a4bca 2. 51f4964 3. 574f052 4. 0edeb06 5. fb208a8 6. c1c363f 7. 98e1159 8. 10cc12a 9. ff4ead5 10. 535b7c8 11. 4b86376 12. 3165046 13. 66a76f3 14. ca19b06 15. 60b7f1c 16. 1eed0f1 17. 5958409 18. 4b9b6fa
2 parents 6b4a82b + 4b9b6fa commit a9b473d

File tree

5 files changed

+166
-43
lines changed

5 files changed

+166
-43
lines changed

app/code/Magento/Checkout/view/frontend/web/template/form/element/email.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
method="post">
1515
<fieldset id="customer-email-fieldset" class="fieldset" data-bind="blockLoader: isLoading">
1616
<div class="field required">
17-
<label class="label" for="customer-email">
18-
<span data-bind="i18n: 'Email Address'"></span>
19-
</label>
17+
<label class="label" for="customer-email"><span data-bind="i18n: 'Email Address'"></span></label>
2018
<div class="control _with-tooltip">
2119
<input class="input-text"
2220
type="email"
@@ -35,9 +33,7 @@
3533
<!--Hidden fields -->
3634
<fieldset class="fieldset hidden-fields" data-bind="fadeVisible: isPasswordVisible">
3735
<div class="field">
38-
<label class="label" for="customer-password">
39-
<span data-bind="i18n: 'Password'"></span>
40-
</label>
36+
<label class="label" for="customer-password"><span data-bind="i18n: 'Password'"></span></label>
4137
<div class="control">
4238
<input class="input-text"
4339
data-bind="
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\ViewModel;
8+
9+
use Magento\Directory\Helper\Data as DataHelper;
10+
use Magento\Customer\Helper\Address as AddressHelper;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\View\Element\Block\ArgumentInterface;
13+
14+
/**
15+
* Custom address view model
16+
*/
17+
class Address implements ArgumentInterface
18+
{
19+
/**
20+
* @var DataHelper
21+
*/
22+
private $helperData;
23+
24+
/**
25+
* @var AddressHelper
26+
*/
27+
private $helperAddress;
28+
29+
/**
30+
* Constructor
31+
*
32+
* @param DataHelper $helperData
33+
* @param AddressHelper $helperAddress
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
35+
*/
36+
public function __construct(
37+
DataHelper $helperData,
38+
AddressHelper $helperAddress
39+
) {
40+
$this->helperData= $helperData;
41+
$this->helperAddress= $helperAddress;
42+
}
43+
44+
/**
45+
* Get string with frontend validation classes for attribute
46+
*
47+
* @param string $attributeCode
48+
* @return string
49+
* @throws \Magento\Framework\Exception\LocalizedException
50+
*/
51+
public function dataGetAttributeValidationClass($attributeCode)
52+
{
53+
return $this->helperData->getAttributeValidationClass($attributeCode);
54+
}
55+
56+
/**
57+
* Get string with frontend validation classes for attribute
58+
*
59+
* @param string $attributeCode
60+
* @return string
61+
* @throws \Magento\Framework\Exception\LocalizedException
62+
*/
63+
public function addressGetAttributeValidationClass($attributeCode)
64+
{
65+
return $this->helperAddress->getAttributeValidationClass($attributeCode);
66+
}
67+
68+
/**
69+
* Return Number of Lines in a Street Address for store
70+
*
71+
* @param \Magento\Store\Model\Store|int|string $store
72+
*
73+
* @return int
74+
* @throws NoSuchEntityException
75+
* @throws \Magento\Framework\Exception\LocalizedException
76+
*/
77+
public function addressGetStreetLines()
78+
{
79+
return $this->helperAddress->getStreetLines();
80+
}
81+
82+
/**
83+
* Check if VAT ID address attribute has to be shown on frontend (on Customer Address management forms)
84+
*
85+
* @return boolean
86+
*/
87+
public function addressIsVatAttributeVisible()
88+
{
89+
return $this->helperAddress->isVatAttributeVisible();
90+
}
91+
92+
/**
93+
* Retrieve regions data json
94+
*
95+
* @return string
96+
* @throws NoSuchEntityException
97+
*/
98+
public function dataGetRegionJson()
99+
{
100+
return $this->helperData->getRegionJson();
101+
}
102+
103+
/**
104+
* Return ISO2 country codes, which have optional Zip/Postal pre-configured
105+
*
106+
* @param bool $asJson
107+
* @return array|string
108+
*/
109+
public function dataGetCountriesWithOptionalZip($asJson)
110+
{
111+
return $this->helperData->getCountriesWithOptionalZip($asJson);
112+
}
113+
}

app/code/Magento/Customer/view/frontend/layout/customer_address_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<arguments>
2222
<argument name="attribute_data" xsi:type="object">Magento\Customer\Block\DataProviders\AddressAttributeData</argument>
2323
<argument name="post_code_config" xsi:type="object">Magento\Customer\Block\DataProviders\PostCodesPatternsAttributeData</argument>
24+
<argument name="view_model" xsi:type="object">Magento\Customer\ViewModel\Address</argument>
2425
</arguments>
2526
</block>
2627
</referenceContainer>

app/code/Magento/Customer/view/frontend/templates/address/edit.phtml

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@
55
*/
66

77
/** @var \Magento\Customer\Block\Address\Edit $block */
8+
/** @var \Magento\Customer\ViewModel\Address $viewModel */
9+
$viewModel = $block->getViewModel();
810
?>
911
<?php $_company = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?>
1012
<?php $_telephone = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?>
1113
<?php $_fax = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?>
14+
<?php $_country_id = $block->getAttributeData()->getFrontendLabel('country_id'); ?>
15+
<?php $_street = $block->getAttributeData()->getFrontendLabel('street'); ?>
16+
<?php $_city = $block->getAttributeData()->getFrontendLabel('city'); ?>
17+
<?php $_region = $block->getAttributeData()->getFrontendLabel('region'); ?>
18+
<?php $_selectRegion = 'Please select a region, state or province.'; ?>
19+
<?php $_displayAll = $block->getConfig('general/region/display_all'); ?>
20+
21+
<?php $_vatidValidationClass = $viewModel->addressGetAttributeValidationClass('vat_id'); ?>
22+
<?php $_cityValidationClass = $viewModel->addressGetAttributeValidationClass('city'); ?>
23+
<?php $_postcodeValidationClass_value = $viewModel->addressGetAttributeValidationClass('postcode'); ?>
24+
<?php $_postcodeValidationClass = $_postcodeValidationClass_value; ?>
25+
<?php $_streetValidationClass = $viewModel->addressGetAttributeValidationClass('street'); ?>
26+
<?php $_streetValidationClassNotRequired = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
27+
<?php $_regionValidationClass = $viewModel->addressGetAttributeValidationClass('region'); ?>
1228
<form class="form-address-edit"
1329
action="<?= $block->escapeUrl($block->getSaveUrl()) ?>"
1430
method="post"
@@ -22,36 +38,32 @@
2238
<input type="hidden" name="error_url" value="<?= $block->escapeUrl($block->getErrorUrl()) ?>">
2339
<?= $block->getNameBlockHtml() ?>
2440

25-
<?php if ($_company->isEnabled()) : ?>
41+
<?php if ($_company->isEnabled()): ?>
2642
<?= $_company->setCompany($block->getAddress()->getCompany())->toHtml() ?>
2743
<?php endif ?>
2844

29-
<?php if ($_telephone->isEnabled()) : ?>
45+
<?php if ($_telephone->isEnabled()): ?>
3046
<?= $_telephone->setTelephone($block->getAddress()->getTelephone())->toHtml() ?>
3147
<?php endif ?>
3248

33-
<?php if ($_fax->isEnabled()) : ?>
49+
<?php if ($_fax->isEnabled()): ?>
3450
<?= $_fax->setFax($block->getAddress()->getFax())->toHtml() ?>
3551
<?php endif ?>
3652

3753
</fieldset>
3854
<fieldset class="fieldset">
3955
<legend class="legend"><span><?= $block->escapeHtml(__('Address')) ?></span></legend><br>
40-
<?php $_streetValidationClass = $this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('street'); ?>
4156
<div class="field street required">
42-
<label for="street_1" class="label">
43-
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?></span>
44-
</label>
57+
<label for="street_1" class="label"><span><?= /* @noEscape */ $_street ?></span></label>
4558
<div class="control">
4659
<input type="text"
4760
name="street[]"
4861
value="<?= $block->escapeHtmlAttr($block->getStreetLine(1)) ?>"
49-
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?>"
62+
title="<?= /* @noEscape */ $_street ?>"
5063
id="street_1"
5164
class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>"/>
5265
<div class="nested">
53-
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
54-
<?php for ($_i = 1, $_n = $this->helper(\Magento\Customer\Helper\Address::class)->getStreetLines(); $_i < $_n; $_i++) : ?>
66+
<?php for ($_i = 1, $_n = $viewModel->addressGetStreetLines(); $_i < $_n; $_i++): ?>
5567
<div class="field additional">
5668
<label class="label" for="street_<?= /* @noEscape */ $_i + 1 ?>">
5769
<span><?= $block->escapeHtml(__('Street Address %1', $_i + 1)) ?></span>
@@ -61,15 +73,16 @@
6173
value="<?= $block->escapeHtmlAttr($block->getStreetLine($_i + 1)) ?>"
6274
title="<?= $block->escapeHtmlAttr(__('Street Address %1', $_i + 1)) ?>"
6375
id="street_<?= /* @noEscape */ $_i + 1 ?>"
64-
class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
76+
class="input-text
77+
<?= $block->escapeHtmlAttr($_streetValidationClassNotRequired) ?>">
6578
</div>
6679
</div>
6780
<?php endfor; ?>
6881
</div>
6982
</div>
7083
</div>
7184

72-
<?php if ($this->helper(\Magento\Customer\Helper\Address::class)->isVatAttributeVisible()) : ?>
85+
<?php if ($viewModel->addressIsVatAttributeVisible()): ?>
7386
<div class="field taxvat">
7487
<label class="label" for="vat_id">
7588
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?></span>
@@ -79,38 +92,41 @@
7992
name="vat_id"
8093
value="<?= $block->escapeHtmlAttr($block->getAddress()->getVatId()) ?>"
8194
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?>"
82-
class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('vat_id')) ?>"
95+
class="input-text <?= $block->escapeHtmlAttr($_vatidValidationClass) ?>"
8396
id="vat_id">
8497
</div>
8598
</div>
8699
<?php endif; ?>
87100
<div class="field city required">
88-
<label class="label" for="city"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('city') ?></span></label>
101+
<label class="label" for="city"><span><?= /* @noEscape */ $_city ?></span></label>
89102
<div class="control">
90103
<input type="text"
91104
name="city"
92105
value="<?= $block->escapeHtmlAttr($block->getAddress()->getCity()) ?>"
93106
title="<?= $block->escapeHtmlAttr(__('City')) ?>"
94-
class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('city')) ?>"
107+
class="input-text <?= $block->escapeHtmlAttr($_cityValidationClass) ?>"
95108
id="city">
96109
</div>
97110
</div>
98111
<div class="field region required">
99112
<label class="label" for="region_id">
100-
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?></span>
113+
<span><?= /* @noEscape */ $_region ?></span>
101114
</label>
102115
<div class="control">
103116
<select id="region_id" name="region_id"
104-
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
105-
class="validate-select region_id" <?= /* @noEscape */ !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>>
106-
<option value=""><?= $block->escapeHtml(__('Please select a region, state or province.')) ?></option>
117+
title="<?= /* @noEscape */ $_region ?>"
118+
class="validate-select region_id"
119+
<?= /* @noEscape */ !$_displayAll ? ' disabled="disabled"' : '' ?>>
120+
<option value=""><?= $block->escapeHtml(__($_selectRegion)) ?></option>
107121
</select>
108122
<input type="text"
109123
id="region"
110124
name="region"
111125
value="<?= $block->escapeHtmlAttr($block->getRegion()) ?>"
112-
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
113-
class="input-text validate-not-number-first <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
126+
title="<?= /* @noEscape */ $_region ?>"
127+
class="input-text validate-not-number-first
128+
<?= $block->escapeHtmlAttr($_regionValidationClass) ?>"
129+
<?= !$_displayAll ? ' disabled="disabled"' : '' ?>/>
114130
</div>
115131
</div>
116132
<div class="field zip required">
@@ -123,46 +139,47 @@
123139
value="<?= $block->escapeHtmlAttr($block->getAddress()->getPostcode()) ?>"
124140
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?>"
125141
id="zip"
126-
class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('postcode')) ?>">
142+
class="input-text validate-zip-international
143+
<?= $block->escapeHtmlAttr($_postcodeValidationClass) ?>">
127144
<div role="alert" class="message warning" style="display:none">
128145
<span></span>
129146
</div>
130147
</div>
131148
</div>
132149
<div class="field country required">
133-
<label class="label" for="country"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('country_id') ?></span></label>
150+
<label class="label" for="country"><span><?= /* @noEscape */ $_country_id ?></span></label>
134151
<div class="control">
135152
<?= $block->getCountryHtmlSelect() ?>
136153
</div>
137154
</div>
138155

139-
<?php if ($block->isDefaultBilling()) : ?>
156+
<?php if ($block->isDefaultBilling()): ?>
140157
<div class="message info">
141158
<span><?= $block->escapeHtml(__("It's a default billing address.")) ?></span>
142159
</div>
143-
<?php elseif ($block->canSetAsDefaultBilling()) : ?>
160+
<?php elseif ($block->canSetAsDefaultBilling()): ?>
144161
<div class="field choice set billing">
145162
<input type="checkbox" id="primary_billing" name="default_billing" value="1" class="checkbox">
146163
<label class="label" for="primary_billing">
147164
<span><?= $block->escapeHtml(__('Use as my default billing address')) ?></span>
148165
</label>
149166
</div>
150-
<?php else : ?>
167+
<?php else: ?>
151168
<input type="hidden" name="default_billing" value="1" />
152169
<?php endif; ?>
153170

154-
<?php if ($block->isDefaultShipping()) : ?>
171+
<?php if ($block->isDefaultShipping()): ?>
155172
<div class="message info">
156173
<span><?= $block->escapeHtml(__("It's a default shipping address.")) ?></span>
157174
</div>
158-
<?php elseif ($block->canSetAsDefaultShipping()) : ?>
175+
<?php elseif ($block->canSetAsDefaultShipping()): ?>
159176
<div class="field choice set shipping">
160177
<input type="checkbox" id="primary_shipping" name="default_shipping" value="1" class="checkbox">
161178
<label class="label" for="primary_shipping">
162179
<span><?= $block->escapeHtml(__('Use as my default shipping address')) ?></span>
163180
</label>
164181
</div>
165-
<?php else : ?>
182+
<?php else: ?>
166183
<input type="hidden" name="default_shipping" value="1">
167184
<?php endif; ?>
168185
</fieldset>
@@ -191,14 +208,14 @@
191208
},
192209
"#country": {
193210
"regionUpdater": {
194-
"optionalRegionAllowed": <?= /* @noEscape */ $block->getConfig('general/region/display_all') ? 'true' : 'false' ?>,
211+
"optionalRegionAllowed": <?= /* @noEscape */ $_displayAll ? 'true' : 'false' ?>,
195212
"regionListId": "#region_id",
196213
"regionInputId": "#region",
197214
"postcodeId": "#zip",
198215
"form": "#form-validate",
199-
"regionJson": <?= /* @noEscape */ $this->helper(\Magento\Directory\Helper\Data::class)->getRegionJson() ?>,
216+
"regionJson": <?= /* @noEscape */ $viewModel->dataGetRegionJson() ?>,
200217
"defaultRegion": "<?= (int) $block->getRegionId() ?>",
201-
"countriesWithOptionalZip": <?= /* @noEscape */ $this->helper(\Magento\Directory\Helper\Data::class)->getCountriesWithOptionalZip(true) ?>
218+
"countriesWithOptionalZip": <?= /* @noEscape */ $viewModel->dataGetCountriesWithOptionalZip(true) ?>
202219
}
203220
}
204221
}

app/code/Magento/Ui/view/frontend/web/templates/form/field.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
-->
77
<div class="field" data-bind="visible: visible, attr: {'name': element.dataScope}, css: additionalClasses">
88

9-
<label class="label" data-bind="attr: { for: element.uid }">
10-
<!-- ko if: element.label -->
11-
<span translate="element.label"></span>
12-
<!-- /ko -->
13-
</label>
9+
<label class="label" data-bind="attr: { for: element.uid }"><!-- ko if: element.label --><span translate="element.label"></span><!-- /ko --></label>
1410

1511
<div class="control" data-bind="css: {'_with-tooltip': element.tooltip}">
1612
<!-- ko ifnot: element.hasAddons() -->

0 commit comments

Comments
 (0)