Skip to content

Commit

Permalink
Add trim filter to first, middle and lastname.
Browse files Browse the repository at this point in the history
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: magento#10415
  • Loading branch information
wardcapp committed Jan 2, 2018
1 parent a39e37f commit 207fdb0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
36 changes: 36 additions & 0 deletions app/code/Magento/Customer/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Customer" setup_version="2.0.12">
<module name="Magento_Customer" setup_version="2.0.13">
<sequence>
<module name="Magento_Eav"/>
<module name="Magento_Directory"/>
Expand Down
37 changes: 37 additions & 0 deletions lib/internal/Magento/Framework/Data/Form/Filter/Trim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/**
* Form Input/Output Trim Filter
*
* @author Magento Core Team <core@magentocommerce.com>
*/
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;
}
}

0 comments on commit 207fdb0

Please sign in to comment.