Skip to content

Commit 5f54bae

Browse files
committed
MAGETWO-86530: [Port to 2.3-develop] Add trim filter to first, middle and lastname. #13012
- Merge Pull Request #13012 from wardcapp/magento2:magento-2.3/patch-github-10415 - Merged commits: 1. e8dad7a 2. 9a45695 3. 03f250a
2 parents 38b2773 + 03f250a commit 5f54bae

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

app/code/Magento/Customer/Setup/UpgradeData.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
159159
$this->upgradeVersionTwoZeroTwelve($customerSetup);
160160
}
161161

162+
if (version_compare($context->getVersion(), '2.0.13', '<')) {
163+
$this->upgradeVersionTwoZeroThirteen($customerSetup);
164+
}
165+
162166
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
163167
$indexer->reindexAll();
164168
$this->eavConfig->clear();
@@ -663,4 +667,36 @@ private function upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup)
663667
['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD]
664668
);
665669
}
670+
671+
/**
672+
* @param CustomerSetup $customerSetup
673+
*/
674+
private function upgradeVersionTwoZeroThirteen(CustomerSetup $customerSetup)
675+
{
676+
$entityAttributes = [
677+
'customer_address' => [
678+
'firstname' => [
679+
'input_filter' => 'trim'
680+
],
681+
'lastname' => [
682+
'input_filter' => 'trim'
683+
],
684+
'middlename' => [
685+
'input_filter' => 'trim'
686+
],
687+
],
688+
'customer' => [
689+
'firstname' => [
690+
'input_filter' => 'trim'
691+
],
692+
'lastname' => [
693+
'input_filter' => 'trim'
694+
],
695+
'middlename' => [
696+
'input_filter' => 'trim'
697+
],
698+
],
699+
];
700+
$this->upgradeAttributes($entityAttributes, $customerSetup);
701+
}
666702
}

app/code/Magento/Customer/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Customer" setup_version="2.0.12">
9+
<module name="Magento_Customer" setup_version="2.0.13">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Directory"/>

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getAttributeMetadataDataProvider()
6363
Customer::FIRSTNAME,
6464
[
6565
AttributeMetadata::FRONTEND_INPUT => 'text',
66-
AttributeMetadata::INPUT_FILTER => '',
66+
AttributeMetadata::INPUT_FILTER => 'trim',
6767
AttributeMetadata::STORE_LABEL => 'First Name',
6868
AttributeMetadata::MULTILINE_COUNT => 0,
6969
AttributeMetadata::VALIDATION_RULES => [
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Form Input/Output Trim Filter
9+
*
10+
* @author Magento Core Team <core@magentocommerce.com>
11+
*/
12+
namespace Magento\Framework\Data\Form\Filter;
13+
14+
class Trim implements \Magento\Framework\Data\Form\Filter\FilterInterface
15+
{
16+
/**
17+
* Returns the result of filtering $value
18+
*
19+
* @param string $value
20+
* @return string
21+
*/
22+
public function inputFilter($value)
23+
{
24+
return trim($value, ' ');
25+
}
26+
27+
/**
28+
* Returns the result of filtering $value
29+
*
30+
* @param string $value
31+
* @return string
32+
*/
33+
public function outputFilter($value)
34+
{
35+
return $value;
36+
}
37+
}

0 commit comments

Comments
 (0)