From 207fdb030ea15b670ee356e0fc6d64168f991dec Mon Sep 17 00:00:00 2001 From: Ward Cappelle Date: Wed, 3 Jan 2018 00:02:37 +0100 Subject: [PATCH 1/3] Add trim filter to first, middle and lastname. The additional trim form field data filter was created and added as input filter to the firstname, lastname and middlename fields of the customer_address and customer entities. Tickets: #10415 --- .../Magento/Customer/Setup/UpgradeData.php | 36 ++++++++++++++++++ app/code/Magento/Customer/etc/module.xml | 2 +- .../Framework/Data/Form/Filter/Trim.php | 37 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 lib/internal/Magento/Framework/Data/Form/Filter/Trim.php 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/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..95f654adbe67f --- /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; + } +} \ No newline at end of file From 2a23a945d0dc40a295ecf679d84c1356a8c27a1c Mon Sep 17 00:00:00 2001 From: Ward Cappelle Date: Wed, 3 Jan 2018 18:53:02 +0100 Subject: [PATCH 2/3] Add new line to end of file Added required new line at the end of the Magento\Framework\Data\Form\Filter\Trim class. See build reports for PR #12964 --- lib/internal/Magento/Framework/Data/Form/Filter/Trim.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php b/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php index 95f654adbe67f..0dbbcf6dbf8d0 100644 --- a/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php +++ b/lib/internal/Magento/Framework/Data/Form/Filter/Trim.php @@ -34,4 +34,4 @@ public function outputFilter($value) { return $value; } -} \ No newline at end of file +} From 1a77bfc9244de2537dfcddf9d1295ceca7a8bd5d Mon Sep 17 00:00:00 2001 From: Matthias Zeis Date: Sun, 7 Jan 2018 16:13:59 +0100 Subject: [PATCH 3/3] Fix customer metadata integration test --- .../testsuite/Magento/Customer/Api/CustomerMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 => [