1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Form multiline text elements
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Framework\Data\Form\Element;
use Magento\Framework\Escaper;
class Multiline extends AbstractElement
{
/**
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
$data = []
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->setType('text');
$this->setLineCount(2);
}
/**
* @return string[]
*/
public function getHtmlAttributes()
{
return [
'type',
'title',
'class',
'style',
'onclick',
'onchange',
'disabled',
'maxlength',
'data-form-part',
'data-role',
'data-action'
];
}
/**
* @param int $suffix
* @param string $scopeLabel
* @return string
*/
public function getLabelHtml($suffix = 0, $scopeLabel = '')
{
return parent::getLabelHtml($suffix, $scopeLabel);
}
/**
* Get element HTML
*
* @return string
*/
public function getElementHtml()
{
$html = '';
$lineCount = $this->getLineCount();
for ($i = 0; $i < $lineCount; $i++) {
if ($i == 0 && $this->getRequired()) {
$this->setClass('input-text admin__control-text required-entry _required');
} else {
$this->setClass('input-text admin__control-text');
}
$html .= '<div class="multi-input admin__field-control"><input id="' .
$this->getHtmlId() .
$i .
'" name="' .
$this->getName() .
'[' .
$i .
']' .
'" value="' .
$this->getEscapedValue(
$i
) . '" ' . $this->serialize(
$this->getHtmlAttributes()
) . ' ' . $this->_getUiId(
$i
) . '/>' . "\n";
if ($i == 0) {
$html .= $this->getAfterElementHtml();
}
$html .= '</div>';
}
return $html;
}
/**
* @return mixed
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function getDefaultHtml()
{
$html = '';
$lineCount = $this->getLineCount();
for ($i = 0; $i < $lineCount; $i++) {
$html .= $this->getNoSpan() === true ? '' : '<span class="field-row">' . "\n";
if ($i == 0) {
$html .= '<label for="' .
$this->getHtmlId() .
$i .
'">' .
$this->getLabel() .
($this->getRequired() ? ' <span class="required">*</span>' : '') .
'</label>' .
"\n";
if ($this->getRequired()) {
$this->setClass('input-text required-entry');
}
} else {
$this->setClass('input-text');
$html .= '<label> </label>' . "\n";
}
$html .= '<input id="' .
$this->getHtmlId() .
$i .
'" name="' .
$this->getName() .
'[' .
$i .
']' .
'" value="' .
$this->getEscapedValue(
$i
) . '"' . $this->serialize(
$this->getHtmlAttributes()
) . ' />' . "\n";
if ($i == 0) {
$html .= $this->getAfterElementHtml();
}
$html .= $this->getNoSpan() === true ? '' : '</span>' . "\n";
}
return $html;
}
/**
* {@inheritdoc}
*/
public function getEscapedValue($index = null)
{
$value = $this->getValue();
if (is_string($value)) {
$value = explode("\n", $value);
if (is_array($value)) {
$this->setValue($value);
}
}
return parent::getEscapedValue($index);
}
}