Skip to content

Commit e7e156c

Browse files
committed
MC-36785: Unable to set YouTube API key by CLI
1 parent 0442e1b commit e7e156c

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

app/code/Magento/Config/App/Config/Source/ModularConfigSource.php

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\Config\App\Config\Source;
77

8+
use Magento\Config\Model\Config\Structure\Reader as ConfigStructureReader;
9+
use Magento\Framework\App\Area;
810
use Magento\Framework\App\Config\ConfigSourceInterface;
911
use Magento\Framework\DataObject;
10-
use Magento\Framework\App\Config\Initial\Reader;
12+
use Magento\Framework\App\Config\Initial\Reader as InitialConfigReader;
1113

1214
/**
1315
* Class for retrieving initial configuration from modules
@@ -18,16 +20,25 @@
1820
class ModularConfigSource implements ConfigSourceInterface
1921
{
2022
/**
21-
* @var Reader
23+
* @var InitialConfigReader
2224
*/
23-
private $reader;
25+
private $initialConfigReader;
2426

2527
/**
26-
* @param Reader $reader
28+
* @var ConfigStructureReader
2729
*/
28-
public function __construct(Reader $reader)
29-
{
30-
$this->reader = $reader;
30+
private $configStructureReader;
31+
32+
/**
33+
* @param InitialConfigReader $initialConfigReader
34+
* @param ConfigStructureReader $configStructureReader
35+
*/
36+
public function __construct(
37+
InitialConfigReader $initialConfigReader,
38+
ConfigStructureReader $configStructureReader
39+
) {
40+
$this->initialConfigReader = $initialConfigReader;
41+
$this->configStructureReader = $configStructureReader;
3142
}
3243

3344
/**
@@ -39,10 +50,51 @@ public function __construct(Reader $reader)
3950
*/
4051
public function get($path = '')
4152
{
42-
$data = new DataObject($this->reader->read());
53+
$initialConfig = $this->initialConfigReader->read();
54+
$configStructure = $this->configStructureReader->read(Area::AREA_ADMINHTML);
55+
$sections = $configStructure['config']['system']['sections'] ?? [];
56+
$defaultConfig = $initialConfig['data']['default'] ?? [];
57+
$initialConfig['data']['default'] = $this->merge($defaultConfig, $sections);
58+
59+
$data = new DataObject($initialConfig);
4360
if ($path !== '') {
4461
$path = '/' . $path;
4562
}
4663
return $data->getData('data' . $path) ?: [];
4764
}
65+
66+
private function addPathKey(array $data, string $path): array
67+
{
68+
if (strpos($path, '/') !== false) {
69+
list ($key, $subPath) = explode('/', $path, 2);
70+
$data[$key] = $this->addPathKey($data[$key] ?? [], $subPath);
71+
} else {
72+
$data += [$path => null];
73+
}
74+
75+
return $data;
76+
}
77+
78+
/**
79+
* Merge initial config with config structure
80+
*
81+
* @param array $config
82+
* @param array $sections
83+
* @return array
84+
*/
85+
private function merge(array $config, array $sections): array
86+
{
87+
foreach ($sections as $key => $section) {
88+
if (isset($section['children'])) {
89+
$config[$section['id']] = $this->merge(
90+
$config[$section['id']] ?? [],
91+
$section['children']
92+
);
93+
} elseif ($section['_elementType'] === 'field') {
94+
$config += [$section['id'] => null];
95+
}
96+
}
97+
98+
return $config;
99+
}
48100
}

app/code/Magento/ProductVideo/etc/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<play_if_base>0</play_if_base>
1313
<show_related>0</show_related>
1414
<video_auto_restart>0</video_auto_restart>
15-
<youtube_api_key/>
1615
</product_video>
1716
</catalog>
1817
</default>

0 commit comments

Comments
 (0)