Skip to content

Commit 92f84be

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

File tree

5 files changed

+137
-9
lines changed

5 files changed

+137
-9
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Multiline extends Text
1111
{
1212
/**
13-
* {@inheritdoc}
13+
* @inheritDoc
1414
*/
1515
public function extractValue(\Magento\Framework\App\RequestInterface $request)
1616
{
@@ -24,7 +24,8 @@ public function extractValue(\Magento\Framework\App\RequestInterface $request)
2424
}
2525

2626
/**
27-
* {@inheritdoc}
27+
* @inheritDoc
28+
*
2829
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2930
*/
3031
public function validateValue($value)
@@ -43,7 +44,8 @@ public function validateValue($value)
4344
if (!is_array($value)) {
4445
$value = [$value];
4546
}
46-
for ($i = 0; $i < $attribute->getMultilineCount(); $i++) {
47+
$multilineCount = $attribute->getMultilineCount();
48+
for ($i = 0; $i < $multilineCount; $i++) {
4749
if (!isset($value[$i])) {
4850
$value[$i] = null;
4951
}
@@ -57,6 +59,7 @@ public function validateValue($value)
5759
if (!empty($value[$i])) {
5860
$result = parent::validateValue($value[$i]);
5961
if ($result !== true) {
62+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
6063
$errors = array_merge($errors, $result);
6164
}
6265
}
@@ -70,26 +73,28 @@ public function validateValue($value)
7073
}
7174

7275
/**
73-
* {@inheritdoc}
76+
* @inheritDoc
7477
*/
7578
public function compactValue($value)
7679
{
77-
if (!is_array($value)) {
78-
$value = [$value];
80+
if (is_array($value)) {
81+
$value = implode("\n", $value);
7982
}
83+
$value = [$value];
84+
8085
return parent::compactValue($value);
8186
}
8287

8388
/**
84-
* {@inheritdoc}
89+
* @inheritDoc
8590
*/
8691
public function restoreValue($value)
8792
{
8893
return $this->compactValue($value);
8994
}
9095

9196
/**
92-
* {@inheritdoc}
97+
* @inheritDoc
9398
*/
9499
public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
95100
{

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

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

app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
</settings>
142142
</multiselect>
143143
<textarea class="Magento\Ui\Component\Form\Element\Textarea" component="Magento_Ui/js/form/element/textarea" template="ui/form/field"/>
144-
<multiline class="Magento\Ui\Component\Form\Element\Multiline" component="Magento_Ui/js/form/components/group"/>
144+
<multiline class="Magento\Ui\Component\Form\Element\Multiline" component="Magento_Ui/js/form/components/multiline"/>
145145
<range class="Magento\Ui\Component\Form\Element\Range" component="Magento_Ui/js/grid/filters/range"/>
146146
<fileUploader class="Magento\Ui\Component\Form\Element\DataType\Media" component="Magento_Ui/js/form/element/file-uploader" template="ui/form/element/uploader/uploader"/>
147147
<imageUploader class="Magento\Ui\Component\Form\Element\DataType\Media\Image" component="Magento_Ui/js/form/element/image-uploader" template="ui/form/element/uploader/image">
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/**
7+
* @api
8+
*/
9+
define([
10+
'./group'
11+
], function (Group) {
12+
'use strict';
13+
14+
return Group.extend({
15+
defaults: {
16+
links: {
17+
value: '${ $.provider }:${ $.dataScope }'
18+
}
19+
},
20+
21+
/**
22+
* Initialize Multiline component.
23+
*
24+
* @returns {Object}
25+
*/
26+
initialize: function () {
27+
return this._super()
28+
._prepareValue();
29+
},
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
initObservable: function () {
35+
this._super()
36+
.observe('value');
37+
38+
return this;
39+
},
40+
41+
/**
42+
* Prepare value for Multiline options.
43+
*
44+
* @returns {Object} Chainable.
45+
* @private
46+
*/
47+
_prepareValue: function () {
48+
var value = this.value();
49+
50+
if (typeof value === 'string') {
51+
this.value(value.split('\n'));
52+
}
53+
54+
return this;
55+
}
56+
});
57+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'uiRegistry',
8+
'Magento_Ui/js/form/components/multiline'
9+
], function (registry, Constr) {
10+
'use strict';
11+
12+
describe('Magento_Ui/js/form/components/multiline', function () {
13+
var obj,
14+
dataScope = 'data',
15+
providerName = 'provider',
16+
prepareDataProvider = function (value) { // jscs:ignore jsDoc
17+
registry.set(providerName, {
18+
/** Stub */
19+
on: function () {},
20+
/** Stub */
21+
set: function () {},
22+
/** Stub */
23+
get: function () {
24+
return value;
25+
}
26+
});
27+
};
28+
29+
describe('Verify process of preparing value for Multiline options', function () {
30+
it('Check _prepareValue method', function () {
31+
obj = new Constr({
32+
_prepareValue: jasmine.createSpy()
33+
});
34+
35+
expect(obj._prepareValue).toHaveBeenCalled();
36+
});
37+
38+
it('Check array preparation', function () {
39+
var value = ['some_array'];
40+
41+
prepareDataProvider(value);
42+
obj = new Constr({
43+
provider: providerName,
44+
dataScope: dataScope
45+
});
46+
47+
expect(obj.value().slice(0)).toEqual(value);
48+
});
49+
50+
it('Check preparation of string value with line breaks', function () {
51+
var value = '\n222\n';
52+
53+
prepareDataProvider(value);
54+
obj = new Constr({
55+
provider: providerName,
56+
dataScope: dataScope
57+
});
58+
59+
expect(obj.value()).toEqual(['', '222', '']);
60+
});
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)