3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
7
+ declare (strict_types=1 );
8
+
6
9
namespace Magento \PageBuilder \Model ;
7
10
8
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use Magento \Framework \Data \Argument \InterpreterInterface ;
13
+ use Magento \PageBuilder \Model \Config \ContentType \AdditionalData \ProviderInterface ;
9
14
10
15
class Config extends \Magento \Framework \Config \Data implements \Magento \PageBuilder \Model \Config \ConfigInterface
11
16
{
12
17
const IS_PAGEBUILDER_ENABLED = 'cms/pagebuilder/enabled ' ;
13
18
19
+ /**
20
+ * @var InterpreterInterface
21
+ */
22
+ private $ argumentInterpreter ;
23
+
14
24
/**
15
25
* @var ScopeConfigInterface
16
26
*/
@@ -20,15 +30,18 @@ class Config extends \Magento\Framework\Config\Data implements \Magento\PageBuil
20
30
* @param \Magento\PageBuilder\Model\Config\CompositeReader $reader
21
31
* @param \Magento\Framework\Config\CacheInterface $cache
22
32
* @param ScopeConfigInterface $scopeConfig
33
+ * @param InterpreterInterface $argumentInterpreter
23
34
* @param string $cacheId
24
35
*/
25
36
public function __construct (
26
37
\Magento \PageBuilder \Model \Config \CompositeReader $ reader ,
27
38
\Magento \Framework \Config \CacheInterface $ cache ,
28
39
ScopeConfigInterface $ scopeConfig ,
40
+ InterpreterInterface $ argumentInterpreter ,
29
41
$ cacheId = 'pagebuilder_config '
30
42
) {
31
43
$ this ->scopeConfig = $ scopeConfig ;
44
+ $ this ->argumentInterpreter = $ argumentInterpreter ;
32
45
parent ::__construct ($ reader , $ cache , $ cacheId );
33
46
}
34
47
@@ -43,22 +56,63 @@ public function getGroups()
43
56
/**
44
57
* Return all content types
45
58
*
46
- * @return array|mixed|null
59
+ * @return array
47
60
*/
48
- public function getContentTypes ()
61
+ public function getContentTypes (): array
49
62
{
50
- return $ this ->get ('types ' );
63
+ $ types = $ this ->get ('types ' );
64
+ $ types = $ this ->parseAdditionalData ($ types );
65
+
66
+ return $ types ;
51
67
}
52
68
53
69
/**
54
70
* Returns config setting if page builder enabled
55
71
*
56
72
* @return bool
57
73
*/
58
- public function isEnabled ()
74
+ public function isEnabled (): bool
59
75
{
60
76
return (bool )$ this ->scopeConfig ->getValue (
61
77
\Magento \PageBuilder \Model \Config::IS_PAGEBUILDER_ENABLED
62
78
);
63
79
}
80
+
81
+ /**
82
+ * Convert and evaluate additional data from arguments nodes to array
83
+ *
84
+ * @param array $types
85
+ * @return array
86
+ */
87
+ private function parseAdditionalData (array $ types ): array
88
+ {
89
+ $ convertToProviders = function ($ additionalDatum ) use (&$ convertToProviders ) {
90
+ $ processedData = [];
91
+
92
+ foreach ($ additionalDatum as $ key => $ value ) {
93
+ if (is_array ($ value )) {
94
+ $ processedData [$ key ] = $ convertToProviders ($ additionalDatum [$ key ]);
95
+ } elseif (is_object ($ value ) && $ value instanceof ProviderInterface) {
96
+ $ processedData [$ key ] = $ value ->getData ($ key )[$ key ];
97
+ } else {
98
+ $ processedData [$ key ] = $ value ;
99
+ }
100
+ }
101
+
102
+ return $ processedData ;
103
+ };
104
+
105
+ foreach ($ types as &$ type ) {
106
+ if (!isset ($ type ['additional_data ' ])) {
107
+ continue ;
108
+ }
109
+
110
+ foreach ($ type ['additional_data ' ] as &$ additionalDatum ) {
111
+ $ additionalDatum = $ this ->argumentInterpreter ->evaluate ($ additionalDatum );
112
+ $ additionalDatum = $ convertToProviders ($ additionalDatum );
113
+ }
114
+ }
115
+
116
+ return $ types ;
117
+ }
64
118
}
0 commit comments