1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2024 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
namespace Magento \Theme \Ui \Component \Design \Config ;
7
7
8
8
use Magento \Framework \Api \FilterBuilder ;
9
9
use Magento \Framework \Api \Search \ReportingInterface ;
10
10
use Magento \Framework \Api \Search \SearchCriteriaBuilder ;
11
11
use Magento \Framework \App \RequestInterface ;
12
+ use Magento \Framework \App \ResourceConnection ;
12
13
use Magento \Store \Model \StoreManagerInterface ;
13
14
14
15
/**
@@ -25,6 +26,11 @@ class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvi
25
26
*/
26
27
protected $ storeManager ;
27
28
29
+ /**
30
+ * @var ResourceConnection
31
+ */
32
+ private $ resourceConnection ;
33
+
28
34
/**
29
35
* @param string $name
30
36
* @param string $primaryFieldName
@@ -34,6 +40,7 @@ class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvi
34
40
* @param RequestInterface $request
35
41
* @param FilterBuilder $filterBuilder
36
42
* @param StoreManagerInterface $storeManager
43
+ * @param ResourceConnection $resourceConnection
37
44
* @param array $meta
38
45
* @param array $data
39
46
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -47,6 +54,7 @@ public function __construct(
47
54
RequestInterface $ request ,
48
55
FilterBuilder $ filterBuilder ,
49
56
StoreManagerInterface $ storeManager ,
57
+ ResourceConnection $ resourceConnection ,
50
58
array $ meta = [],
51
59
array $ data = []
52
60
) {
@@ -62,6 +70,7 @@ public function __construct(
62
70
$ data
63
71
);
64
72
$ this ->storeManager = $ storeManager ;
73
+ $ this ->resourceConnection = $ resourceConnection ;
65
74
}
66
75
67
76
/**
@@ -87,11 +96,38 @@ public function getData()
87
96
->create ()
88
97
);
89
98
}
99
+
100
+ $ themeConfigData = $ this ->getCoreConfigData ();
90
101
$ data = parent ::getData ();
91
102
foreach ($ data ['items ' ] as & $ item ) {
92
103
$ item += ['default ' => __ ('Global ' )];
104
+
105
+ $ scope = ($ item ['store_id ' ]) ? 'stores ' : (($ item ['store_website_id ' ]) ? 'websites ' : 'default ' );
106
+ $ scopeId = (int ) $ item ['store_website_id ' ] ?? 0 ;
107
+ $ themeId = (int ) $ item ['theme_theme_id ' ] ?? 0 ;
108
+
109
+ $ criteria = ['scope ' => $ scope , 'scope_id ' => $ scopeId , 'value ' => $ themeId ];
110
+ $ configData = array_filter ($ themeConfigData , function ($ themeConfig ) use ($ criteria ) {
111
+ return array_intersect_assoc ($ criteria , $ themeConfig ) === $ criteria ;
112
+ });
113
+
114
+ $ item += ['short_description ' => !$ configData ? __ ('Using Default Theme ' ) : '' ];
93
115
}
94
116
95
117
return $ data ;
96
118
}
119
+
120
+ /**
121
+ * Get the core config data related to theme
122
+ *
123
+ * @return array
124
+ */
125
+ private function getCoreConfigData (): array
126
+ {
127
+ $ connection = $ this ->resourceConnection ->getConnection ();
128
+ return $ connection ->fetchAll (
129
+ $ connection ->select ()->from ($ connection ->getTableName ('core_config_data ' ))
130
+ ->where ('path = ? ' , 'design/theme/theme_id ' )
131
+ );
132
+ }
97
133
}
0 commit comments