Skip to content

Commit a9d515a

Browse files
committed
MC-23554: Customer custom multiline attribute displays incorrectly
1 parent 92f84be commit a9d515a

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Session\SessionManagerInterface;
1818
use Magento\Customer\Model\FileUploaderDataResolver;
1919
use Magento\Customer\Model\AttributeMetadataResolver;
20+
use Magento\Ui\Component\Form\Element\Multiline;
2021
use Magento\Ui\DataProvider\AbstractDataProvider;
2122

2223
/**
@@ -130,6 +131,7 @@ public function getData(): array
130131
$result['customer'],
131132
array_flip(self::$forbiddenCustomerFields)
132133
);
134+
$this->prepareCustomAttributeValue($result['customer']);
133135
unset($result['address']);
134136

135137
$result['default_billing_address'] = $this->prepareDefaultAddress(
@@ -179,6 +181,24 @@ private function prepareDefaultAddress($address): array
179181
return $addressData;
180182
}
181183

184+
/***
185+
* Prepare values for Custom Attributes.
186+
*
187+
* @param array $data
188+
* @return void
189+
*/
190+
private function prepareCustomAttributeValue(array &$data): void
191+
{
192+
foreach ($this->meta['customer']['children'] as $attributeName => $attributeMeta) {
193+
if ($attributeMeta['arguments']['data']['config']['dataType'] === Multiline::NAME
194+
&& isset($data[$attributeName])
195+
&& !is_array($data[$attributeName])
196+
) {
197+
$data[$attributeName] = explode("\n", $data[$attributeName]);
198+
}
199+
}
200+
}
201+
182202
/**
183203
* Get attributes meta
184204
*

app/code/Magento/Customer/Model/Metadata/Form/Multiline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function validateValue($value)
7878
public function compactValue($value)
7979
{
8080
if (is_array($value)) {
81-
$value = implode("\n", $value);
81+
$value = trim(implode("\n", $value));
8282
}
8383
$value = [$value];
8484

app/code/Magento/Ui/Component/Form/Element/Multiline.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function prepare()
6666
{
6767
$size = abs((int) $this->getData('config/size'));
6868
$validation = [$this->getData('config/validation')];
69-
$namespace = $this->getContext()->getNamespace();
7069
while ($size--) {
7170
$identifier = $this->getName() . '_' . $size;
7271
$arguments = [
@@ -75,8 +74,6 @@ public function prepare()
7574
'config' => [
7675
'dataScope' => $size,
7776
'dataType' => static::DATA_TYPE,
78-
'deps' => "{$namespace}.areas.customer.customer.{$this->getName()}",
79-
'provider' => $namespace . '.' . $this->getContext()->getDataProvider()->getName(),
8077
'formElement' => static::FORM_ELEMENT,
8178
'sortOrder' => $size,
8279
]

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/components/multiline.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ define([
1717
registry.set(providerName, {
1818
/** Stub */
1919
on: function () {},
20+
2021
/** Stub */
2122
set: function () {},
23+
2224
/** Stub */
2325
get: function () {
2426
return value;
@@ -48,15 +50,15 @@ define([
4850
});
4951

5052
it('Check preparation of string value with line breaks', function () {
51-
var value = '\n222\n';
53+
var value = 'first\n\nthird';
5254

5355
prepareDataProvider(value);
5456
obj = new Constr({
5557
provider: providerName,
5658
dataScope: dataScope
5759
});
5860

59-
expect(obj.value()).toEqual(['', '222', '']);
61+
expect(obj.value()).toEqual(['first', '', 'third']);
6062
});
6163
});
6264
});

0 commit comments

Comments
 (0)