5
5
*/
6
6
namespace Magento \Config \App \Config \Source ;
7
7
8
+ use Magento \Config \Model \Config \Structure \Reader as ConfigStructureReader ;
9
+ use Magento \Framework \App \Area ;
8
10
use Magento \Framework \App \Config \ConfigSourceInterface ;
9
11
use Magento \Framework \DataObject ;
10
- use Magento \Framework \App \Config \Initial \Reader ;
12
+ use Magento \Framework \App \Config \Initial \Reader as InitialConfigReader ;
11
13
12
14
/**
13
15
* Class for retrieving initial configuration from modules
18
20
class ModularConfigSource implements ConfigSourceInterface
19
21
{
20
22
/**
21
- * @var Reader
23
+ * @var InitialConfigReader
22
24
*/
23
- private $ reader ;
25
+ private $ initialConfigReader ;
24
26
25
27
/**
26
- * @param Reader $reader
28
+ * @var ConfigStructureReader
27
29
*/
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 ;
31
42
}
32
43
33
44
/**
@@ -39,10 +50,51 @@ public function __construct(Reader $reader)
39
50
*/
40
51
public function get ($ path = '' )
41
52
{
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 );
43
60
if ($ path !== '' ) {
44
61
$ path = '/ ' . $ path ;
45
62
}
46
63
return $ data ->getData ('data ' . $ path ) ?: [];
47
64
}
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
+ }
48
100
}
0 commit comments