Skip to content

Commit 86d46ce

Browse files
committed
MAGETWO-72860: Fix default values not being properly loaded for ArraySerialized fields - for 2.2
1 parent d2d82ac commit 86d46ce

File tree

7 files changed

+353
-85
lines changed

7 files changed

+353
-85
lines changed

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,10 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
425425
if ($placeholderValue) {
426426
$data = $placeholderValue;
427427
}
428+
428429
if ($data === null) {
429-
if (array_key_exists($path, $this->_configData)) {
430-
$data = $this->_configData[$path];
431-
432-
if ($field->hasBackendModel()) {
433-
$backendModel = $field->getBackendModel();
434-
$backendModel->setPath($path)
435-
->setValue($data)
436-
->setWebsite($this->getWebsiteCode())
437-
->setStore($this->getStoreCode())
438-
->afterLoad();
439-
$data = $backendModel->getValue();
440-
}
441-
} elseif ($field->getConfigPath() !== null) {
442-
$data = $this->getConfigValue($field->getConfigPath());
443-
} else {
444-
$data = $this->getConfigValue($path);
445-
}
430+
$path = $field->getConfigPath() !== null ? $field->getConfigPath() : $path;
431+
$data = $this->getConfigValue($path);
446432
}
447433

448434
return $data;

app/code/Magento/Config/Model/Config/Backend/Serialized.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*/
66
namespace Magento\Config\Model\Config\Backend;
77

8+
use Magento\Framework\App\Config\Data\ProcessorInterface;
89
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Serialize\Serializer\Json;
1011

1112
/**
1213
* @api
1314
* @since 100.0.2
1415
*/
15-
class Serialized extends \Magento\Framework\App\Config\Value
16+
class Serialized extends \Magento\Framework\App\Config\Value implements ProcessorInterface
1617
{
1718
/**
1819
* @var Json
@@ -67,4 +68,12 @@ public function beforeSave()
6768
parent::beforeSave();
6869
return $this;
6970
}
71+
72+
/**
73+
* @inheritdoc
74+
*/
75+
public function processValue($value)
76+
{
77+
return empty($value) ? '' : $this->serializer->unserialize($value);
78+
}
7079
}

app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,12 @@ public function initFieldsDataProvider()
543543
return [
544544
[
545545
['section1/group1/field1' => 'some_value'],
546-
false,
547-
null,
546+
'some_value',
547+
'section1/group1/field1',
548548
false,
549549
'some_value',
550550
null,
551-
1,
551+
0,
552552
false,
553553
false,
554554
false
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Config\Block\System\Config;
8+
9+
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
10+
11+
/**
12+
* Backend system config array field renderer for integration test.
13+
*/
14+
class FieldArray extends AbstractFieldArray
15+
{
16+
/**
17+
* @inheritdoc
18+
*/
19+
protected function _toHtml()
20+
{
21+
$value = '';
22+
$element = $this->getElement();
23+
if ($element->getValue() && is_array($element->getValue())) {
24+
$value = implode('|', $element->getValue());
25+
}
26+
27+
return sprintf(
28+
'<input id="%s" name="%s" value="%s" />',
29+
$element->getId(),
30+
$element->getName(),
31+
$value
32+
);
33+
}
34+
}

0 commit comments

Comments
 (0)