Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extraneous whitespace - #26275 #26285

Merged
merged 18 commits into from Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
method="post">
<fieldset id="customer-email-fieldset" class="fieldset" data-bind="blockLoader: isLoading">
<div class="field required">
<label class="label" for="customer-email">
<span data-bind="i18n: 'Email Address'"></span>
</label>
<label class="label" for="customer-email"><span data-bind="i18n: 'Email Address'"></span></label>
<div class="control _with-tooltip">
<input class="input-text"
type="email"
Expand All @@ -35,9 +33,7 @@
<!--Hidden fields -->
<fieldset class="fieldset hidden-fields" data-bind="fadeVisible: isPasswordVisible">
<div class="field">
<label class="label" for="customer-password">
<span data-bind="i18n: 'Password'"></span>
</label>
<label class="label" for="customer-password"><span data-bind="i18n: 'Password'"></span></label>
<div class="control">
<input class="input-text"
data-bind="
Expand Down
113 changes: 113 additions & 0 deletions app/code/Magento/Customer/ViewModel/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\ViewModel;

use Magento\Directory\Helper\Data as DataHelper;
use Magento\Customer\Helper\Address as AddressHelper;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* Custom address view model
*/
class Address implements ArgumentInterface
{
/**
* @var DataHelper
*/
private $helperData;
DanielRuf marked this conversation as resolved.
Show resolved Hide resolved

/**
* @var AddressHelper
DanielRuf marked this conversation as resolved.
Show resolved Hide resolved
*/
private $helperAddress;

/**
* Constructor
*
* @param DataHelper $helperData
* @param AddressHelper $helperAddress
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
DataHelper $helperData,
AddressHelper $helperAddress
) {
$this->helperData= $helperData;
$this->helperAddress= $helperAddress;
}

/**
DanielRuf marked this conversation as resolved.
Show resolved Hide resolved
* Get string with frontend validation classes for attribute
*
* @param string $attributeCode
* @return string
DanielRuf marked this conversation as resolved.
Show resolved Hide resolved
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function dataGetAttributeValidationClass($attributeCode)
{
return $this->helperData->getAttributeValidationClass($attributeCode);
}

/**
DanielRuf marked this conversation as resolved.
Show resolved Hide resolved
* Get string with frontend validation classes for attribute
*
* @param string $attributeCode
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function addressGetAttributeValidationClass($attributeCode)
{
return $this->helperAddress->getAttributeValidationClass($attributeCode);
}

/**
* Return Number of Lines in a Street Address for store
*
* @param \Magento\Store\Model\Store|int|string $store
*
* @return int
* @throws NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function addressGetStreetLines()
{
return $this->helperAddress->getStreetLines();
}

/**
* Check if VAT ID address attribute has to be shown on frontend (on Customer Address management forms)
*
* @return boolean
*/
public function addressIsVatAttributeVisible()
{
return $this->helperAddress->isVatAttributeVisible();
}

/**
* Retrieve regions data json
*
* @return string
* @throws NoSuchEntityException
*/
public function dataGetRegionJson()
{
return $this->helperData->getRegionJson();
}

/**
* Return ISO2 country codes, which have optional Zip/Postal pre-configured
*
* @param bool $asJson
* @return array|string
*/
public function dataGetCountriesWithOptionalZip($asJson)
{
return $this->helperData->getCountriesWithOptionalZip($asJson);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<arguments>
<argument name="attribute_data" xsi:type="object">Magento\Customer\Block\DataProviders\AddressAttributeData</argument>
<argument name="post_code_config" xsi:type="object">Magento\Customer\Block\DataProviders\PostCodesPatternsAttributeData</argument>
<argument name="view_model" xsi:type="object">Magento\Customer\ViewModel\Address</argument>
</arguments>
</block>
</referenceContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@
*/

/** @var \Magento\Customer\Block\Address\Edit $block */
/** @var \Magento\Customer\ViewModel\Address $viewModel */
$viewModel = $block->getViewModel();
?>
<?php $_company = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?>
<?php $_telephone = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?>
<?php $_fax = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?>
<?php $_country_id = $block->getAttributeData()->getFrontendLabel('country_id'); ?>
<?php $_street = $block->getAttributeData()->getFrontendLabel('street'); ?>
<?php $_city = $block->getAttributeData()->getFrontendLabel('city'); ?>
<?php $_region = $block->getAttributeData()->getFrontendLabel('region'); ?>
<?php $_selectRegion = 'Please select a region, state or province.'; ?>
<?php $_displayAll = $block->getConfig('general/region/display_all'); ?>

<?php $_vatidValidationClass = $viewModel->addressGetAttributeValidationClass('vat_id'); ?>
<?php $_cityValidationClass = $viewModel->addressGetAttributeValidationClass('city'); ?>
<?php $_postcodeValidationClass_value = $viewModel->addressGetAttributeValidationClass('postcode'); ?>
<?php $_postcodeValidationClass = $_postcodeValidationClass_value; ?>
<?php $_streetValidationClass = $viewModel->addressGetAttributeValidationClass('street'); ?>
<?php $_streetValidationClassNotRequired = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php $_regionValidationClass = $viewModel->addressGetAttributeValidationClass('region'); ?>
<form class="form-address-edit"
action="<?= $block->escapeUrl($block->getSaveUrl()) ?>"
method="post"
Expand All @@ -22,36 +38,32 @@
<input type="hidden" name="error_url" value="<?= $block->escapeUrl($block->getErrorUrl()) ?>">
<?= $block->getNameBlockHtml() ?>

<?php if ($_company->isEnabled()) : ?>
<?php if ($_company->isEnabled()): ?>
<?= $_company->setCompany($block->getAddress()->getCompany())->toHtml() ?>
<?php endif ?>

<?php if ($_telephone->isEnabled()) : ?>
<?php if ($_telephone->isEnabled()): ?>
<?= $_telephone->setTelephone($block->getAddress()->getTelephone())->toHtml() ?>
<?php endif ?>

<?php if ($_fax->isEnabled()) : ?>
<?php if ($_fax->isEnabled()): ?>
<?= $_fax->setFax($block->getAddress()->getFax())->toHtml() ?>
<?php endif ?>

</fieldset>
<fieldset class="fieldset">
<legend class="legend"><span><?= $block->escapeHtml(__('Address')) ?></span></legend><br>
<?php $_streetValidationClass = $this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('street'); ?>
<div class="field street required">
<label for="street_1" class="label">
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?></span>
</label>
<label for="street_1" class="label"><span><?= /* @noEscape */ $_street ?></span></label>
<div class="control">
<input type="text"
name="street[]"
value="<?= $block->escapeHtmlAttr($block->getStreetLine(1)) ?>"
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('street') ?>"
title="<?= /* @noEscape */ $_street ?>"
id="street_1"
class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>"/>
<div class="nested">
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 1, $_n = $this->helper(\Magento\Customer\Helper\Address::class)->getStreetLines(); $_i < $_n; $_i++) : ?>
<?php for ($_i = 1, $_n = $viewModel->addressGetStreetLines(); $_i < $_n; $_i++): ?>
<div class="field additional">
<label class="label" for="street_<?= /* @noEscape */ $_i + 1 ?>">
<span><?= $block->escapeHtml(__('Street Address %1', $_i + 1)) ?></span>
Expand All @@ -61,15 +73,16 @@
value="<?= $block->escapeHtmlAttr($block->getStreetLine($_i + 1)) ?>"
title="<?= $block->escapeHtmlAttr(__('Street Address %1', $_i + 1)) ?>"
id="street_<?= /* @noEscape */ $_i + 1 ?>"
class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
class="input-text
<?= $block->escapeHtmlAttr($_streetValidationClassNotRequired) ?>">
</div>
</div>
<?php endfor; ?>
</div>
</div>
</div>

<?php if ($this->helper(\Magento\Customer\Helper\Address::class)->isVatAttributeVisible()) : ?>
<?php if ($viewModel->addressIsVatAttributeVisible()): ?>
<div class="field taxvat">
<label class="label" for="vat_id">
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?></span>
Expand All @@ -79,38 +92,41 @@
name="vat_id"
value="<?= $block->escapeHtmlAttr($block->getAddress()->getVatId()) ?>"
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('vat_id') ?>"
class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('vat_id')) ?>"
class="input-text <?= $block->escapeHtmlAttr($_vatidValidationClass) ?>"
id="vat_id">
</div>
</div>
<?php endif; ?>
<div class="field city required">
<label class="label" for="city"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('city') ?></span></label>
<label class="label" for="city"><span><?= /* @noEscape */ $_city ?></span></label>
<div class="control">
<input type="text"
name="city"
value="<?= $block->escapeHtmlAttr($block->getAddress()->getCity()) ?>"
title="<?= $block->escapeHtmlAttr(__('City')) ?>"
class="input-text <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('city')) ?>"
class="input-text <?= $block->escapeHtmlAttr($_cityValidationClass) ?>"
id="city">
</div>
</div>
<div class="field region required">
<label class="label" for="region_id">
<span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?></span>
<span><?= /* @noEscape */ $_region ?></span>
</label>
<div class="control">
<select id="region_id" name="region_id"
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
class="validate-select region_id" <?= /* @noEscape */ !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>>
<option value=""><?= $block->escapeHtml(__('Please select a region, state or province.')) ?></option>
title="<?= /* @noEscape */ $_region ?>"
class="validate-select region_id"
<?= /* @noEscape */ !$_displayAll ? ' disabled="disabled"' : '' ?>>
<option value=""><?= $block->escapeHtml(__($_selectRegion)) ?></option>
</select>
<input type="text"
id="region"
name="region"
value="<?= $block->escapeHtmlAttr($block->getRegion()) ?>"
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('region') ?>"
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"' : '' ?>/>
title="<?= /* @noEscape */ $_region ?>"
class="input-text validate-not-number-first
<?= $block->escapeHtmlAttr($_regionValidationClass) ?>"
<?= !$_displayAll ? ' disabled="disabled"' : '' ?>/>
</div>
</div>
<div class="field zip required">
Expand All @@ -123,46 +139,47 @@
value="<?= $block->escapeHtmlAttr($block->getAddress()->getPostcode()) ?>"
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?>"
id="zip"
class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper(\Magento\Customer\Helper\Address::class)->getAttributeValidationClass('postcode')) ?>">
class="input-text validate-zip-international
<?= $block->escapeHtmlAttr($_postcodeValidationClass) ?>">
<div role="alert" class="message warning" style="display:none">
<span></span>
</div>
</div>
</div>
<div class="field country required">
<label class="label" for="country"><span><?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('country_id') ?></span></label>
<label class="label" for="country"><span><?= /* @noEscape */ $_country_id ?></span></label>
<div class="control">
<?= $block->getCountryHtmlSelect() ?>
</div>
</div>

<?php if ($block->isDefaultBilling()) : ?>
<?php if ($block->isDefaultBilling()): ?>
<div class="message info">
<span><?= $block->escapeHtml(__("It's a default billing address.")) ?></span>
</div>
<?php elseif ($block->canSetAsDefaultBilling()) : ?>
<?php elseif ($block->canSetAsDefaultBilling()): ?>
<div class="field choice set billing">
<input type="checkbox" id="primary_billing" name="default_billing" value="1" class="checkbox">
<label class="label" for="primary_billing">
<span><?= $block->escapeHtml(__('Use as my default billing address')) ?></span>
</label>
</div>
<?php else : ?>
<?php else: ?>
<input type="hidden" name="default_billing" value="1" />
<?php endif; ?>

<?php if ($block->isDefaultShipping()) : ?>
<?php if ($block->isDefaultShipping()): ?>
<div class="message info">
<span><?= $block->escapeHtml(__("It's a default shipping address.")) ?></span>
</div>
<?php elseif ($block->canSetAsDefaultShipping()) : ?>
<?php elseif ($block->canSetAsDefaultShipping()): ?>
<div class="field choice set shipping">
<input type="checkbox" id="primary_shipping" name="default_shipping" value="1" class="checkbox">
<label class="label" for="primary_shipping">
<span><?= $block->escapeHtml(__('Use as my default shipping address')) ?></span>
</label>
</div>
<?php else : ?>
<?php else: ?>
<input type="hidden" name="default_shipping" value="1">
<?php endif; ?>
</fieldset>
Expand Down Expand Up @@ -191,14 +208,14 @@
},
"#country": {
"regionUpdater": {
"optionalRegionAllowed": <?= /* @noEscape */ $block->getConfig('general/region/display_all') ? 'true' : 'false' ?>,
"optionalRegionAllowed": <?= /* @noEscape */ $_displayAll ? 'true' : 'false' ?>,
"regionListId": "#region_id",
"regionInputId": "#region",
"postcodeId": "#zip",
"form": "#form-validate",
"regionJson": <?= /* @noEscape */ $this->helper(\Magento\Directory\Helper\Data::class)->getRegionJson() ?>,
"regionJson": <?= /* @noEscape */ $viewModel->dataGetRegionJson() ?>,
"defaultRegion": "<?= (int) $block->getRegionId() ?>",
"countriesWithOptionalZip": <?= /* @noEscape */ $this->helper(\Magento\Directory\Helper\Data::class)->getCountriesWithOptionalZip(true) ?>
"countriesWithOptionalZip": <?= /* @noEscape */ $viewModel->dataGetCountriesWithOptionalZip(true) ?>
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
-->
<div class="field" data-bind="visible: visible, attr: {'name': element.dataScope}, css: additionalClasses">

<label class="label" data-bind="attr: { for: element.uid }">
<!-- ko if: element.label -->
<span translate="element.label"></span>
<!-- /ko -->
</label>
<label class="label" data-bind="attr: { for: element.uid }"><!-- ko if: element.label --><span translate="element.label"></span><!-- /ko --></label>

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