Skip to content

Commit a49f524

Browse files
committed
#7822: Empty Checkout Agreement Edit Form when Single Store Mode is enabled
1 parent a39e37f commit a49f524

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,13 @@ public function getElementHtml()
353353
$html .= '<label class="addbefore" for="' . $htmlId . '">' . $beforeElementHtml . '</label>';
354354
}
355355

356-
$html .= '<input id="' . $htmlId . '" name="' . $this->getName() . '" ' . $this->_getUiId() . ' value="' .
357-
$this->getEscapedValue() . '" ' . $this->serialize($this->getHtmlAttributes()) . '/>';
356+
if (is_array($this->getValue())) {
357+
foreach ($this->getValue() as $value) {
358+
$html .= $this->getHtmlForInputByValue($this->_escape($value));
359+
}
360+
} else {
361+
$html .= $this->getHtmlForInputByValue($this->getEscapedValue());
362+
}
358363

359364
$afterElementJs = $this->getAfterElementJs();
360365
if ($afterElementJs) {
@@ -574,4 +579,17 @@ public function isLocked()
574579
{
575580
return $this->getData($this->lockHtmlAttribute) == 1;
576581
}
582+
583+
/**
584+
* Get input html by sting value.
585+
*
586+
* @param string $value
587+
*
588+
* @return string
589+
*/
590+
private function getHtmlForInputByValue(string $value)
591+
{
592+
return '<input id="' . $this->getHtmlId() . '" name="' . $this->getName() . '" ' . $this->_getUiId()
593+
. ' value="' . $value . '" ' . $this->serialize($this->getHtmlAttributes()) . '/>';
594+
}
577595
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Test\Unit\Data;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
/**
12+
* Test for \Magento\Framework\Data\Form\Element\Hidden.
13+
*/
14+
class HiddenTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var \Magento\Framework\Data\Form\Element\Hidden
18+
*/
19+
private $element;
20+
21+
protected function setUp()
22+
{
23+
$objectManager = new ObjectManager($this);
24+
$this->element = $objectManager->getObject(\Magento\Framework\Data\Form\Element\Hidden::class);
25+
}
26+
27+
/**
28+
* @param mixed $value
29+
*
30+
* @dataProvider getElementHtmlDataProvider
31+
*/
32+
public function testGetElementHtml($value)
33+
{
34+
$form = $this->createMock(\Magento\Framework\Data\Form::class);
35+
$this->element->setForm($form);
36+
$this->element->setValue($value);
37+
$html = $this->element->getElementHtml();
38+
39+
if (is_array($value)) {
40+
foreach ($value as $item) {
41+
$this->assertContains($item, $html);
42+
}
43+
} else {
44+
$this->assertContains($value, $html);
45+
}
46+
}
47+
48+
public function getElementHtmlDataProvider()
49+
{
50+
return [
51+
['some_value'],
52+
['store_ids[]' => ['1', '2']],
53+
];
54+
}
55+
}

0 commit comments

Comments
 (0)