diff --git a/app/code/Magento/Customer/Setup/UpgradeData.php b/app/code/Magento/Customer/Setup/UpgradeData.php index b5aba18a92f28..0ad36b1d6d11c 100644 --- a/app/code/Magento/Customer/Setup/UpgradeData.php +++ b/app/code/Magento/Customer/Setup/UpgradeData.php @@ -159,6 +159,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $this->upgradeVersionTwoZeroTwelve($customerSetup); } + if (version_compare($context->getVersion(), '2.0.13', '<')) { + $this->upgradeVersionTwoZeroThirteen($customerSetup); + } + $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); $indexer->reindexAll(); $this->eavConfig->clear(); @@ -663,4 +667,36 @@ private function upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup) ['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD] ); } + + /** + * @param CustomerSetup $customerSetup + */ + private function upgradeVersionTwoZeroThirteen(CustomerSetup $customerSetup) + { + $entityAttributes = [ + 'customer_address' => [ + 'firstname' => [ + 'input_filter' => 'trim' + ], + 'lastname' => [ + 'input_filter' => 'trim' + ], + 'middlename' => [ + 'input_filter' => 'trim' + ], + ], + 'customer' => [ + 'firstname' => [ + 'input_filter' => 'trim' + ], + 'lastname' => [ + 'input_filter' => 'trim' + ], + 'middlename' => [ + 'input_filter' => 'trim' + ], + ], + ]; + $this->upgradeAttributes($entityAttributes, $customerSetup); + } } diff --git a/app/code/Magento/Customer/etc/module.xml b/app/code/Magento/Customer/etc/module.xml index 3f0d42b12649a..2dfe561d0da8f 100644 --- a/app/code/Magento/Customer/etc/module.xml +++ b/app/code/Magento/Customer/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php b/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php index 4ee936f83f537..f2632aa1481e4 100644 --- a/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php @@ -63,7 +63,7 @@ public function getAttributeMetadataDataProvider() Customer::FIRSTNAME, [ AttributeMetadata::FRONTEND_INPUT => 'text', - AttributeMetadata::INPUT_FILTER => '', + AttributeMetadata::INPUT_FILTER => 'trim', AttributeMetadata::STORE_LABEL => 'First Name', AttributeMetadata::MULTILINE_COUNT => 0, AttributeMetadata::VALIDATION_RULES => [ diff --git a/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php b/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php new file mode 100644 index 0000000000000..0dbbcf6dbf8d0 --- /dev/null +++ b/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php @@ -0,0 +1,37 @@ + + */ +namespace Magento\Framework\Data\Form\Filter; + +class Trim implements \Magento\Framework\Data\Form\Filter\FilterInterface +{ + /** + * Returns the result of filtering $value + * + * @param string $value + * @return string + */ + public function inputFilter($value) + { + return trim($value, ' '); + } + + /** + * Returns the result of filtering $value + * + * @param string $value + * @return string + */ + public function outputFilter($value) + { + return $value; + } +}