Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Multiline.php
Go to the documentation of this file.
1 <?php
13 
15 
17 {
24  public function __construct(
25  Factory $factoryElement,
26  CollectionFactory $factoryCollection,
27  Escaper $escaper,
28  $data = []
29  ) {
30  parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
31  $this->setType('text');
32  $this->setLineCount(2);
33  }
34 
38  public function getHtmlAttributes()
39  {
40  return [
41  'type',
42  'title',
43  'class',
44  'style',
45  'onclick',
46  'onchange',
47  'disabled',
48  'maxlength',
49  'data-form-part',
50  'data-role',
51  'data-action'
52  ];
53  }
54 
60  public function getLabelHtml($suffix = 0, $scopeLabel = '')
61  {
62  return parent::getLabelHtml($suffix, $scopeLabel);
63  }
64 
70  public function getElementHtml()
71  {
72  $html = '';
73  $lineCount = $this->getLineCount();
74 
75  for ($i = 0; $i < $lineCount; $i++) {
76  if ($i == 0 && $this->getRequired()) {
77  $this->setClass('input-text admin__control-text required-entry _required');
78  } else {
79  $this->setClass('input-text admin__control-text');
80  }
81  $html .= '<div class="multi-input admin__field-control"><input id="' .
82  $this->getHtmlId() .
83  $i .
84  '" name="' .
85  $this->getName() .
86  '[' .
87  $i .
88  ']' .
89  '" value="' .
90  $this->getEscapedValue(
91  $i
92  ) . '" ' . $this->serialize(
93  $this->getHtmlAttributes()
94  ) . ' ' . $this->_getUiId(
95  $i
96  ) . '/>' . "\n";
97  if ($i == 0) {
98  $html .= $this->getAfterElementHtml();
99  }
100  $html .= '</div>';
101  }
102  return $html;
103  }
104 
109  public function getDefaultHtml()
110  {
111  $html = '';
112  $lineCount = $this->getLineCount();
113 
114  for ($i = 0; $i < $lineCount; $i++) {
115  $html .= $this->getNoSpan() === true ? '' : '<span class="field-row">' . "\n";
116  if ($i == 0) {
117  $html .= '<label for="' .
118  $this->getHtmlId() .
119  $i .
120  '">' .
121  $this->getLabel() .
122  ($this->getRequired() ? ' <span class="required">*</span>' : '') .
123  '</label>' .
124  "\n";
125  if ($this->getRequired()) {
126  $this->setClass('input-text required-entry');
127  }
128  } else {
129  $this->setClass('input-text');
130  $html .= '<label>&nbsp;</label>' . "\n";
131  }
132  $html .= '<input id="' .
133  $this->getHtmlId() .
134  $i .
135  '" name="' .
136  $this->getName() .
137  '[' .
138  $i .
139  ']' .
140  '" value="' .
141  $this->getEscapedValue(
142  $i
143  ) . '"' . $this->serialize(
144  $this->getHtmlAttributes()
145  ) . ' />' . "\n";
146  if ($i == 0) {
147  $html .= $this->getAfterElementHtml();
148  }
149  $html .= $this->getNoSpan() === true ? '' : '</span>' . "\n";
150  }
151  return $html;
152  }
153 
157  public function getEscapedValue($index = null)
158  {
159  $value = $this->getValue();
160  if (is_string($value)) {
161  $value = explode("\n", $value);
162  if (is_array($value)) {
163  $this->setValue($value);
164  }
165  }
166 
167  return parent::getEscapedValue($index);
168  }
169 }
$suffix
Definition: name.phtml:27
__construct(Factory $factoryElement, CollectionFactory $factoryCollection, Escaper $escaper, $data=[])
Definition: Multiline.php:24
getLabelHtml($suffix=0, $scopeLabel='')
Definition: Multiline.php:60
$value
Definition: gender.phtml:16
serialize($attributes=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
$i
Definition: gallery.phtml:31
$index
Definition: list.phtml:44