diff --git a/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php b/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php index 8db84c27980ad..a8451e43ade20 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php @@ -353,8 +353,13 @@ public function getElementHtml() $html .= ''; } - $html .= '_getUiId() . ' value="' . - $this->getEscapedValue() . '" ' . $this->serialize($this->getHtmlAttributes()) . '/>'; + if (is_array($this->getValue())) { + foreach ($this->getValue() as $value) { + $html .= $this->getHtmlForInputByValue($this->_escape($value)); + } + } else { + $html .= $this->getHtmlForInputByValue($this->getEscapedValue()); + } $afterElementJs = $this->getAfterElementJs(); if ($afterElementJs) { @@ -574,4 +579,17 @@ public function isLocked() { return $this->getData($this->lockHtmlAttribute) == 1; } + + /** + * Get input html by sting value. + * + * @param string|null $value + * + * @return string + */ + private function getHtmlForInputByValue($value) + { + return '_getUiId() + . ' value="' . $value . '" ' . $this->serialize($this->getHtmlAttributes()) . '/>'; + } } diff --git a/lib/internal/Magento/Framework/Test/Unit/Data/Form/Element/HiddenTest.php b/lib/internal/Magento/Framework/Test/Unit/Data/Form/Element/HiddenTest.php new file mode 100644 index 0000000000000..023070d4d69d6 --- /dev/null +++ b/lib/internal/Magento/Framework/Test/Unit/Data/Form/Element/HiddenTest.php @@ -0,0 +1,55 @@ +element = $objectManager->getObject(\Magento\Framework\Data\Form\Element\Hidden::class); + } + + /** + * @param mixed $value + * + * @dataProvider getElementHtmlDataProvider + */ + public function testGetElementHtml($value) + { + $form = $this->createMock(\Magento\Framework\Data\Form::class); + $this->element->setForm($form); + $this->element->setValue($value); + $html = $this->element->getElementHtml(); + + if (is_array($value)) { + foreach ($value as $item) { + $this->assertContains($item, $html); + } + return; + } + $this->assertContains($value, $html); + } + + public function getElementHtmlDataProvider() + { + return [ + ['some_value'], + ['store_ids[]' => ['1', '2']], + ]; + } +}